草庐IT

non-struct

全部标签

c++ - 'struct std::pair<int, int >' has no member named ' 序列化'

我正在尝试将序列化集成到我的代码中。但是,我收到“没有命名的成员”错误。我正在阅读的书说std::pair不需要包含头文件并且不存在。如何修复此错误?我的代码如下所示:#include//ofstream/ifstream#include#include#include//stringstream#include//#include#include//#includeusingnamespacestd;intmain(){complexc(1,0);bitsetb(BOOST_BINARY(101));pairp(1,2);strings;std::stringstreamss(s);

c++ - C++11 中的 POD 和继承。 struct的地址是否==第一个成员的地址?

(我已经编辑了这个问题以避免分心。在任何其他问题变得有意义之前,有一个核心问题需要被澄清。向那些现在回答似乎不太相关的人道歉。)让我们设置一个具体的例子:structBase{inti;};没有虚方法,也没有继承,一般是一个很笨很简单的对象。因此它是PlainOldData(POD)它回到了可预测的布局。特别是:Baseb;&b==reinterpret_cast&(b.i);这是根据Wikipedia(它本身声称引用了C++03标准):ApointertoaPOD-structobject,suitablyconvertedusingareinterpretcast,pointsto

c++ - 那么现在 struct 可以有虚函数并支持继承吗?那么与 classes 有什么区别呢?信息隐藏的真正目的是什么?

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:WhatarethedifferencesbetweenstructandclassinC++http://www.cplusplus.com/reference/std/typeinfo/type_info/我想我的“老师”并没有告诉我很多关于C++中结构和类之间的区别。我在其他一些关于继承的问题中读到,默认情况下结构是公共(public)的...我也猜想结构没有构造函数/析构函数...那么还有哪些区别呢?它们有那么重要吗?当谈到私有(private)/protected属性/方法时,它们在运行时不可访问,

c++ - (Re)Using std::algorithms with non-standard containers

我有一个“列”容器类型:structMyColumnType{//Data:Eachrowrepresentsamemberofanobject.vectora;//Allvectorsareguaranteedtohavealwaysvectorb;//thesamelength.vectorc;voidcopy(intfrom_pos,intto_pos);//Thecolumntypeprovidesaninterfacevoidswap(intpos_a,intpos_b);//forcopying,swapping,...voidpush_back();//Andforres

c++ - MSVC : modifiers not allowed on non-memberfunction

我在linux下编写了一个信号/插槽库(Codeprojectarticlehere),同时使用Clang3.5和GCC4.9进行编译。它在两个编译器上编译时都没有警告(也在3.4版和4.8版上)。当我完成所有工作并将文章发布到网上时,没过多久我就收到投诉说它不能在MSVC上工作。(VisualStudioExpress2013?对不起,我对版本控制系统不熟悉。)我把它安装在虚拟机中自己看了一下,发现它不会编译以下内容:templatestructRemoveCV;templatestructRemoveCV{usingType=R(Args...);};templatestructR

C++:使用int vs struct对静态成员变量进行依赖初始化的静态

给定一个从另一个类的静态成员变量初始化的静态成员变量,非文字structii有时默认初始化为0或到333。这取决于编译或链接顺序。伪代码演示:classStaticClass://file'ONE.cpp/.hpp'staticinti=2staticstructii{inta=333}classABC://file'abc.cpp'staticintabc_i=StaticClass::i//always2staticstructabc_ii=StaticClass::ii//sometimes0,sometimes333调用g++-std=c++11abc.cppONE.cpp&&

c++ - 为什么 long long union 成员的对齐比包含的 union/struct 大?这个对吗?

来自thisquestion人们可能会开始相信union的一致性不亚于其个体成员的最大一致性。但是我对gcc/g++中的longlong类型有疑问。可以找到完整的示例here,但这里是我的问题的相关部分:unionull{longlongm;};structsll{longlongm;};intmain(){#definepr(v)cout这会产生以下输出:sizeof(longlong):8__alignof__(longlong):8sizeof(ull):8__alignof__(ull):4sizeof(sll):8__alignof__(sll):4为什么union成员的对齐

c++ - 'struct ListNode' 类型的空指针内的成员访问

structListNode{intval;ListNode*next;ListNode(intx):val(x),next(NULL){}};classSolution{public:boolhasCycle(ListNode*head){if(head==NULL)returnfalse;ListNode*walker=head;ListNode*runner=head;while(runner->next!=NULL&&walker->next!=NULL){walker=walker->next;runner=runner->next->next;if(walker==runn

c++ - libc++ 与 VC++ : Can non-UTF conversions be done with wstring_convert?

C++11的std::wstring_convert效果很好*用于标准UTF-8UTF-16/UCS2/UCS4转换。但是,当我尝试使用不是来自的构面实例化wstring_convert或wbuffer_convert时,它没有按预期工作://worksasexpectedstd::wstring_convert>ucs4conv;//Now,byanalogy,Iwanttotrythis:std::wstring_convert>gbconv(newstd::codecvt_byname("zh_CN.gb18030"));Clang++错误提示“在~wstring_convert

c++ - 隐式转换 : const reference vs non-const reference vs non-reference

考虑这段代码,structA{};structB{B(constA&){}};voidf(B){cout这compilesfine,运行良好。但是,如果我将f(B)更改为f(B&),它doesn'tcompile.如果我写f(constB&),它又是compilesfine,运行良好。原因和道理是什么?总结:voidf(B);//okayvoidf(B&);//errorvoidf(constB&);//okay对于每种情况,我想听听语言规范中的原因、基本原理和引用资料。当然,函数签名本身并没有错。A隐式转换为B和constB&,但不会转换为B&,这会导致编译错误。