草庐IT

propery_name

全部标签

c++ - 继承 : expected class-name before ‘{’ token

我试图在C++中创建一个异常类,但它不起作用。我已将代码减少到最少,但仍然找不到错误。这是我的头文件:#ifndefLISTEXCEPTION_H#defineLISTEXCEPTION_H//C++standardlibraries#include/*CLASSDEFINITION*/classListException:publicexception{};#endif//LISTEXCEPTION_H这是我得到的错误:error:expectedclass-namebefore‘{’token这是出乎意料的。我该如何解决这个问题? 最佳答案

c++ - 指向 typeinfo::name() 的内存的生命周期是多少?

在C++中,我可以使用typeid运算符来检索任何多态类的名称:constchar*name=typeid(CMyClass).name();返回的constchar*指针指向的字符串对我的程序可用多长时间? 最佳答案 只要带有rtti的类存在。因此,如果您处理单个可执行文件-永远。但是对于动态链接库中的类,它会发生一点变化。可能你可以卸载它。 关于c++-指向typeinfo::name()的内存的生命周期是多少?,我们在StackOverflow上找到一个类似的问题:

C++ 风格约定 : Parameter Names within Class Declaration

我是一个相当新的C++程序员,我想听听支持和反对在类声明中命名参数的争论。这是一个例子:Student.h#ifndefSTUDENT_H_#defineSTUDENT_H_#includeusingnamespacestd;classStudent{private:stringname;unsignedintage;floatheight,GPA;public:Student(string,unsignedint,float,float);voidsetAge(unsignedint);};#endif/*STUDENT_H_*/对比#ifndefSTUDENT_H_#defineS

c++ - 来自 Xcode 8.3.2 : Non-portable path to file - specified path differs in case from file name on disk 的错误警告

出于某种原因,我的代码库突然开始收到数以千计的此类警告。但到目前为止,所有有问题的文件和路径都是完全正确的,与我在磁盘上看到的与Finder相匹配。他们是不是在暗地里另有幕后?当问题实际上并不存在时,为什么Xcode会生成这些警告?尽管http://stackoverflow.com/questions/43067017/non-portable-path-to-file-file-h-specified-path-differs-in-case-from-file-na是关于相同的警告,在这种情况下我已经验证导入路径与磁盘上的文件名匹配。 最佳答案

c++ - 为什么 injected-class-name 有时不被视为类模板中的模板名称?

SourceInthefollowingcases,theinjected-class-nameistreatedasatemplate-nameoftheclasstemplateitself:itisfollowedbyitisusedasatemplateargumentthatcorrespondstoatemplatetemplateparameteritisthefinalidentifierintheelaboratedclassspecifierofafriendclasstemplatedeclaration.所以我尝试检查所有3种情况(另外在基本歧义的情况下,尽管我

c++ - G++ 4.4.7 中的 "names the constructor, not the type"

我有以下简单的C++代码:#includeclassA{public:A(inty):x(y){}A&operator=(constA&rhs);intx;};A::A&A::operator=(constA&rhs){this->x=rhs.x;return*this;}intmain(int,char**){Aa1(5);Aa2(4);printf("a2.x==%d\n",a2.x);a2=a1;printf("a2.x==%d\n",a2.x);return0;}第11行,A的operator=()函数的定义所在,格式不正确......或者,至少,我相信是这样。正如预期的那样,

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - 为什么将数组作为 "int *& name"传递?

我得到了一个(C++)代码,其中使用数组传递voidfun(int*&name){...}但这背后的想法是什么?我猜它的意思是“一个引用数组”,但是当你只传递一个指向第一个元素的指针时就没问题了,不是吗?那么这样做的动机是什么? 最佳答案 该函数接收对指针的引用。这意味着该函数不仅可以修改name指向的int,还可以修改自身指针函数调用也将在外部可见。例子:#includeint*allocate(){returnnewint();}voiddestroy(int*&ptr){deleteptr;ptr=NULL;}intmain(

c++ - 获取错误 : 'mutex' in namespace 'std' does not name a type in MinGW mysys prompt

我已经从官方网站下载了MinGW并将其安装在我的Windows8.1机器上。运行g++--version给我g++.exe(GCC)4.8.1。我正在尝试在MinGW编译器中编译现有的代码库,但它因以下错误而失败:error:'mutex'innamespace'std'doesnotnameatypeprivate:std::mutexm_Mutex;^error:'condition_variable'innamespace's还有更多与锁定和线程相关的错误。!我能够在Cygwin-64中编译相同的代码库,没有任何问题。我需要在MinGW中成功构建和编译,以便创建一些与MSVS兼容

c++ - 错误 : Expected template-name before '<' token

我正在尝试编译一个实现chain和chainNodes的程序并在以下行(第22行)出现错误:classchain:publiclinearList错误是:Error:expectedtemplate-namebefore'知道为什么会出现这种情况吗?我的代码如下://linkedimplementationofalinearlist//derivesfromabstractclasslinearListjusttomakesure//allmethodsoftheADTareimplemented#ifndefchain_#definechain_#include#include#in