草庐IT

member_joindate

全部标签

C++ : Connecting a member of a class to its definition

我是C++的新手,我在OCaml和Python方面有更多经验。我想通过制作一个玩“MorpionSolitaire”的程序来学习C++。我的开始有点困难。在下面的代码中:typedefenum{NORTH,NORTHEAST,EAST,SOUTHEAST}direction;chardeltax[4]={0,1,1,1};chardeltay[4]={1,1,0,-1};classCoords{private:charx,y;public:Coords(charxx,charyy){x=xx;y=yy;};charget_x()const{returnx;}charget_y()con

c++ - 结构绑定(bind) : binding to public data members (inherited base class )

即使基类和派生类都有公共(public)数据成员#includeclassM{public:intx=2;volatiledoubley=3;};classS:publicM{public:intx1=4;volatiledoubley1=5;};intmain(){Sf();Sa;std::cout获取错误auto[b,c,d,e]=f();main.cpp:Infunction'intmain()':main.cpp:21:10:error:cannotdecomposeclasstype'S':bothitanditsbaseclass'M'havenon-staticdatam

c++ - 抽象类 : invalid abstract return type for member function ‘virtual...’

在我的程序中我有这样的类层次结构:#include#include#includeusingnamespacestd;classaa;classbb;classroot{public:virtual~root(){}virtualrootadd(constaa&a)const=0;virtualrootadd(constbb&a)const=0;};classaa:publicroot{public:aa(){}aa(constaa&a){}virtualrootadd(constaa&a)const{returnroot(newaa());}virtualrootadd(constb

C++: 奇怪的 "Request for member X of Y which is of non-class type Z"

以下程序,用g++4.6编译,产生错误requestformember‘y’in‘a2’,whichisofnon-classtype‘A(B)’最后一行:#includetemplateclassA{public:Ty;A(Tx):y(x){}};classB{public:intu;B(intv):u(v){}};intmain(){intv=10;Bb1(v);//worksAa1(b1);//doesnotwork(theerroriswhena2isused)Aa2(B(v));//works//Aa2((B(v)));std::cout从代码中包含的工作变体可以看出,在A的

C++ 结构 : more members, 成员访问时间慢得多?

我有一个结构链表。假设我将x百万个节点插入到链表中,然后我遍历所有节点以找到给定值。奇怪的是(至少对我而言),如果我有这样的结构:structnode{inta;node*nxt;};然后我可以遍历列表并检查a的值,这比我在结构中有另一个成员时快十倍,如下所示:structnode_complex{inta;stringb;node_complex*nxt;};我也用C风格的字符串(字符数组)尝试过,结果是一样的:只是因为我有另一个成员(字符串),整个迭代(+值检查)慢了10倍,即使我从来没有碰过那个成员!现在,我不知道结构的内部是如何工作的,但看起来要付出高昂的代价......有什么

c++ - 解决链接器错误 : undefined reference to static class members

我的代码是Arduinoish。我打开了详细编译,这样我就可以验证所有.o文件确实正确地传递给了链接器,并且它们是(下面的链接器命令)。这让我相信这是某种语法错误。谷歌搜索错误“undefinedreferencetoinfunction”会产生很多结果,答案包括“像这样将foo.o添加到您的链接器命令”等。我希望解决方案就像缺少点或->某处一样简单。我在一个文件中收到来自链接器的这一系列错误:SerialServoControl.cpp.o:Infunction`SerialServoControl::send(int,int)':SerialServoControl.cpp:31:

c++ - C2039 : Class is not a member of Namespace

Mage/Interface/Context.h#pragmaonce#include#include#include#includenamespaceMage{namespaceInterface{classContext{protected:RenderingContext*ctx;VertexBuffer*vbo;glm::mat4projection;Mage::Interface::Frame*uiParent;public:Context(RenderingContext*ctx);~Context();voidrender();Mage::Interface::Frame

c++ - C++ 错误 : class has no member named

我有这个问题MemoryBundleStorage.cpp:Inmemberfunction'virtualvoiddtn::storage::MemoryBundleStorage::store(constdtn::data::Bundle&)':MemoryBundleStorage.cpp:146:67:error:'constclassdtn::data::Bundle'hasnomembernamed'getClass'MemoryBundleStorage.cpp:150:19:error:'constclassdtn::data::Bundle'hasnomemberna

c++ - 没有 typedef 的运算符 member_function_pointer_type()?

是否可以在不使用typedef的情况下创建一个operatormember_function_pointer_type()(即通过内联指定成员函数指针的类型)?例如,在实现SafeBoolIdiom时:classFoo{typedefvoid(Foo::*bool_type)()const;public:operatorbool_type()const;};是否可以在声明运算符时直接写出bool_type的类型?如果是,怎么办? 最佳答案 这似乎是唯一不能在不使用typedef的情况下声明(类型转换)operator的情况。如果它是

c++ - boost 智能指针和 BOOST_NO_MEMBER_TEMPLATES

经过一番努力后,我设法获得了boostsmartpointers以在警告级别4为WindowsCE/Mobile构建。我发现消除编译错误和警告的阻力最小的方法是#defineBOOST_NO_MEMBER_TEMPLATES这到底是什么意思?我把我的灵魂卖给了魔鬼吗?当我真正使用这些类型时,一切都会变得一团糟吗? 最佳答案 本身不应该有任何不良影响,只是功能损失。成员模板是作为模板的成员函数,例如:structfoo{templatevoidi_am_not_supported_sometimes(void);};所以你不会得到未定