草庐IT

NAME_CONST

全部标签

c++ - 前向声明 : incomplete type 'enums::Category' used in nested name specifier 有问题

我想要一个围绕枚举的包装器,这将使我有机会将其转换为字符串,反之亦然。基类如下:templateclassStringConvertedEnum{public:staticstd::stringtoString(TEnume);staticTEnumtoEnum(std::string&str);protected:staticconststd::map_stringMapping;staticconststd::map_enumMapping;};然后我想要这样的东西:classCategory:publicStringConvertedEnum{public:enumEnum{Ca

c++ - 对指针的 const 引用可以改变对象

const引用确保您无法更改所引用的对象。例如:inti=1;constint&ref=i;ref=42;//error,becauseofaconstreference但是如果你使用对指针或unique_ptr的引用,你可以。示例:classTinyClass{public:intvar=1;voidf1(){var=42;}};std::unique_ptrpointer(newTinyClass);conststd::unique_ptr&constRef=pointer;constRef->f1();//noerror我假设发生这种情况是因为指针本身没有改变。但是这个感觉mis

c++ - 了解 void f(const T& param) 中参数的类型

引用:EffectiveModernC++Item4.https://github.com/BartVandewoestyne/Effective-Modern-Cpp/blob/master/Item04_Know_how_to_view_deduced_types/runtime_output02.cppclassWidget{};template//templatefunctiontovoidf(constT¶m)//becalled{}std::vectorcreateVec()//factoryfunction{std::vectorvw;Widgetw;vw.pus

c++ - std::result_of 应用于 const 重载方法

如果我给typedefstd::vectorv;然后下面可以用来捕获常量迭代器的类型(另一种方法是使用v::const_iterator,但这取决于const_iterator成员类型在类中明确定义。typedeftypenamestd::result_of::typeconst_iterator;确实,我们可以检查上面的内容是否如我们所愿。static_assert(std::is_same::value);但是,我发现下面的编译器失败。typedeftypenamestd::result_of::typeiterator;编译器提示该方法被重载(通过const修饰符)并且无法明确解

c++ - 为什么这个用于检测类型 T 是否具有 void operator(EDT const&) 的 C++ 特性会失败?

我正在尝试使用SFINAE来检测作为模板参数T传递的类型是否具有T::operator()(Pconst&),其中P也是模板参数。我在MemberDetectorIdiom的这个例子之后为我的解决方案建模不幸的是,我无法让它为operator()工作,即使我可以让它为普通方法工作。下面是一些演示我面临的问题的示例代码:#include#include#include#includeusingnamespacestd;structhas{voidoperator()(intconst&);};structhasNot1{voidoperator()(int);};structhasNot

c++ - 带有尾随返回类型的 final、override、const 的语法

我正在尝试覆盖虚拟,但也使用关键字override、final和const,以及尾随返回类型。问题似乎出在派生类中,编译器错误(说我没有指定尾随返回类型)并没有太大帮助。代码在这里:https://wandbox.org/permlink/zh3hD4Ukgrg6txyE也贴在下面。我玩过不同的顺序,但似乎仍然无法正确处理。任何帮助将不胜感激,谢谢。#includeusingstd::cout;usingstd::endl;usingstd::ostream;////////////////////////////////////////////////BasestuffclassBa

c++ - const char * 与其他指针不同吗?

这个问题在这里已经有了答案:Whydoescoutprintchararraysdifferentlyfromotherarrays?(4个答案)关闭4年前。所以我最近一直在深入研究指针和引用,因为它们经常出现在我用来学习OpenGL的资源中。我注意到constchar*指针的行为似乎与其他指针有些不同。为了演示,我创建了这个测试程序:#includeintmain(){inti=2;int*pi;//constcharc="helloworld";constchar*pc="helloworld";pi=&i;std::cout输出:'helloworld'typeischarcon

【LaTeX 问题解决方案】I couldn‘t open file name `.aux‘

最近用vscode的latex插件编译论文的时候发现,编译bibtex时总会报错:Icouldn’topenfilename“.aux”。但是在编译xelatex时发现已经产生了一个aux文件,那么为什么latex插件无法找到aux文件呢?经过一番摸索,我发现问题出现在设置文件中。"latex-workshop.latex.clean.fileTypes":[//"*.aux","*.bbl","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gl

c++ - 模板 :Name resolution:Point of instantiation: -->can any one tell some more examples for this statement?

这是来自ISOC++标准14.6.4.1实例化点的声明Forafunctiontemplatespecialization,amemberfunctiontemplatespecialization,oraspecializationforamemberfunctionorstaticdatamemberofaclasstemplate,ifthespecializationisimplicitlyinstantiatedbecauseitisreferencedfromwithinanothertemplatespecializationandthecontextfromwhichi

c++ - 如何从成员函数模板类型签名中删除 const?

我正在研究一些C++类型系统的东西,但我在从成员函数中删除const-ness以用于函数特征类时遇到问题。真正麻烦的是,这在G++中运行良好,但MSVC10无法正确处理部分特化,我不知道这些编译器中的一个是否真的存在错误。这里的问题是,以我可以获得函数类型签名的方式从成员函数中删除const限定符的正确方法是什么?采用以下代码示例:#includetemplatestructRemovePointer{typedefTType;};templatestructRemovePointer{typedefTType;};templatestructRemovePointer{typedef