草庐IT

class-attributes

全部标签

C++ 模板 "class type"错误

我一直在研究一个链表模板类来对各种变量做同样的事情,并设法解决了大部分问题。除了编译时,我得到这些:g++-Wall-otemplate_testtemplate_test.cppInfileincludedfromtemplate_test.cpp:1:0:LinkedList.h:50:11:error:declarationof‘classType’LinkedList.h:7:11:error:shadowstemplateparm‘classType’LinkedList.h:51:30:error:invaliduseofincompletetype‘classLinked

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

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

c++ - 在 g++ 中使用 __attribute__ 的不平衡括号

今天我在前段时间开发的一个项目上尝试了clang。当它遇到编译错误时我很惊讶,因为我已经使用g++成功编译了我的项目。这个简短的片段重现了遇到错误的行:intmain(){__attribute__((aligned(16))chararr[5];}产生此错误的原因:test.cpp:2:32:error:expected')'__attribute__((aligned(16))chararr[5];^)如您所见,有一个不平衡的括号。有三个“(”和两个“)”。这显然看起来应该会产生编译错误。这是该关键字的有效用法吗?我似乎无法在thedocumentation上找到任何内容这表明它是

c++ - 对齐 : warning C4316 in all classes that have aligned members

今天我遇到了很多麻烦,因为我跟踪了一个非常隐蔽的腐败漏洞。我想如果我真的注意警告就不会那么难找到它,但由于找不到有关为什么弹出此特定警告的相关信息,我让它滑动了,这是一个错误。所以这是VisualStudio2013给我的有罪警告:warningC4316:objectallocatedontheheapmaynotbealigned16它是在通过const引用将align(16)临时传递给构造函数时生成的,如以下代码所示:classVector{};__declspec(align(16))classVectorA{};classShape{public:Shape(constVec

c++ - 我什么时候使用 "__attribute__((nonnull))"与 "not_null<T*>"?

我习惯于使用__attribute__((nonnull))表达不应为空的指针时。voidf(int*ptr)__attribute__((nonnull));intmain(){int*ptr=newint(1);f(ptr);}voidf(int*ptr){/*impl*/}但是,对于GSL,还有not_null包装类型。voidfunction1(gsl::not_nulln);voidf(gsl::not_nulln);intmain(){int*ptr=newint(1);f(ptr);}voidf(gsl::not_nulln){/*impl*/}假设语言设施支持GSL版本

c++ - GMock : How to return mock class variable as the return value

我是第一次尝试使用GMock(用于C++的谷歌模拟框架)。我有以下类(class):classLocalCache{public:virtualtime_tGetCurrentTime()=0;virtualintAddEntry(conststd::stringkey,std::string&value);virtualintGetEntry(conststd::stringkey,std::string&value);};GetEntry方法调用GetCurrentTime调用。我想模拟GetCurrentTime方法,以便我可以在测试中提前时钟以测试作为GetEntry调用的一部

c++ - 为什么 Builder 模式比在正在创建的 Class 对象中带有参数的 Constructor 更好?

为什么我们不能在构造函数本身中执行不同的构建步骤。如果构建步骤采用参数,为什么不能将它们作为参数提供给构造函数并在构造函数中用于创建对象。据我所知,在Builder模式中,客户端要创建哪个特定对象;那么在正在创建的类的对象中使用构建器而不是带有参数的构造函数有什么优势? 最佳答案 哦!我得到它。我正在查看维基百科示例并意识到Builder为何有用。当客户端不知道将哪些参数传递给构造函数时,这很有用,因为它非常复杂,因此无法直接调用构造函数并获取对象。因此,他向ConcreteBuilders寻求帮助,他们知道将哪些参数传递给构造函数

c++ - 移动构造函数和赋值运算符 : why no default for derived classes?

为什么没有为派生类创建默认移动构造函数或赋值运算符?证明我的意思;具有此设置代码:#includestructA{A(){}A(A&&){throw0;}A&operator=(A&&){throw0;}};structB:A{};以下任一行抛出:Ax(std::move(A());Ax;x=A();但以下都没有:Bx(std::move(B());Bx;x=B();以防万一,我使用GCC4.4进行了测试。编辑:后来使用GCC4.5进行的测试显示了相同的行为。 最佳答案 通读0xFCD中的12.8(12.8/17特别是移动构造函数)

c# - "C# base class virtual function"- "override in Managed C++ ref class"

我有一个.NET_4ManagedC++ref类,它派生自用C#编写的.NET_4基类。C#基类:namespaceCore{publicclassResourceManager{publicclass_Resource{publicvirtualvoidDelete(){}}}}托管C++类:namespaceInput.DI{publicrefclassMouse:ResourceManager::_Resource{public:virtualvoidDelete(){}};}这是我遇到的错误:'Input::DI::Mouse::Delete':matchesbaserefcl

c++ - 多重继承 : size of class for virtual pointers?

给定代码:classA{};classB:publicvirtualA{};classC:publicvirtualA{};classD:publicB,publicC{};intmain(){cout输出:sizeof(D)8每个类都包含自己的虚指针,但不包含其任何基类的虚指针,那么,为什么class(D)的Size是8? 最佳答案 这取决于编译器的实现。我的编译器是VisualStdioC++2005。代码如下:intmain(){cout会输出sizeof(B):4sizeof(C):4sizeof(D):8B类只有一个虚指针