草庐IT

派生词

全部标签

c++ - 如何派生新参数并将其添加到构造函数的基本版本?

我试图用一些数据成员扩展一个基类,因此除了我的基类需要的构造函数参数之外,还需要一些额外的构造函数参数。我想将第一个构造函数参数转发给基类。这是我尝试过的:#include#includestructX{X(inti_):i(i_){}inti;};structY:X{template//note:candidateconstructornotviable:Y(Ts&&...args,std::strings_)//requiressingleargument's_',but2arguments//^//wereprovided:X(std::forward(args)...),s(s

c++ - 如何制作具有派生行为的模板?

我有一个模板Conditional,它根据bool表达式返回value:templatestructConditional{};templatestructConditional{typedefC1value;};templatestructConditional{typedefC2value;};,Int>::value;//Int,Int>::value,//Int我想制作一个ConditionalInteger模板,他的行为源自ConditionConditionalInteger::value==0;//trueConditionalInteger::value==1//fal

C++ 面向对象 - 类的继承与派生

目录        公有继承——学生信息类保护继承——学生信息类研究生信息类狼人类公有继承——学生信息类编程要求在右侧编辑器中的Begin-End之间补充代码,设计Student类,并实现Set和PrintSID函数,具体要求如下:Student类公有成员函数:voidPrintSID(),函数输出成员变量SID的值,输出格式为:学号:SID。普通函数:Set(intsid,stringname,Student*ptr),它用前两个参数设置ptr对象的SID和Name(继承People拥有的属性)属性值。现在已有一个基类People,它有一个公有成员变量姓名Name,一个公有成员函数Print

c++将派生类分配给基类的更好方法

这似乎是一个愚蠢的问题,但我希望能够在一行中实例化派生类并将其分配给基类:classA{};classB:publicA{};//icandothisA*base;Bderived;base=&derived;//i'dliketodosomethinglikethisA*base;base=&B();//producesawarning:takingaddressoftemporary我试图在不使用new运算符的情况下获得多态行为。我认为编译器正在插入对构造函数返回值的临时引用。是否可以指示编译器我实际上想使用该地址进行分配?*编辑这里有一点背景。解析xml文件时,我有这样的事情:c

c++ - 为什么派生构造函数需要基析构函数?

classA{public:A();private:~A();};classB:publicA{public:B(){};private:~B();};intmain(){return0;}我有这样的编译错误:test.cpp:Inconstructor'B::B()':test.cpp:5:4:error:'A::~A()'isprivatetest.cpp:10:8:error:withinthiscontext我知道派生构造函数需要调用基析构函数,因此我将A::A()设置为public。但是,为什么编译器会提示它也需要publicA::~A()? 最佳

c++ - 从标准 :string to add typedefs and enums 派生

对于客户端和服务器之间交换的UDP包,我想支持两种字符串字段:名为cstring的以null结尾的c字符串stringwithprecedinguint8_tsize-fieldnamedvstring为了self记录我们包的布局,我想使用简单的结构声明:structABC{vstringa;cstringb;}然后在反/序列化函数中调用重载函数get(char*,vstring&v)和get(char*,cstring&)如下:voiddeserialize(constchar*bytes,ABC&msg){get(msg.a);get(msg.b);}voidserialize(c

C++:调用派生类的虚函数

假设我有一个带有虚函数的类和一个以不同方式实现虚函数的派生类。假设我还有一个用于存储派生类的基类的vector。在事先不知道派生类是什么的情况下,如何在vector中执行派生类的虚函数?说明问题的最少代码:#include#includeclassFoo{public:virtualvoiddo_stuff(void){std::coutfoo_vector;Barbar;foo_vector.resize(1);foo_vector[0]=bar;bar.do_stuff();/*printsBar*/foo_vector[0].do_stuff();/*printsFoo;shou

ios - 访问属性时 NSManagedObject 派生对象的损坏

我有一个类,它在某个时候通过CoreData获取获取一堆数据,然后插入对象,这些对象是在XCode中以通常的CoreData方式创建的,因此是从NSManagedObject派生的,到一个NSMutableSet。根据事情的进展情况,其中一些对象可能最终会出现在其他几个集合中。到目前为止,一切都很好。但接下来会发生以下情况:NSMutableArray*anArray=[NSMutableArrayalloc]init;[currentResultsminus:previousResults];//bothareNSMutableSetsfor(MyObject*objincurren

ios - NSException 派生类或异常名称列表?

我已经通过了IntroductiontoExceptionProgrammingTopicsforCocoa.在ThrowingExceptions下,显示了一个异常名称:FileNotFoundException:NSException*e=[NSExceptionexceptionWithName:@"FileNotFoundException"reason:@"FileNotFoundonSystem"userInfo:nil];@throwe;然而,PredefinedExceptions页面列出了大约10个异常,FileNotFoundException未列出。在哪里可以找到

ios - Xcode 派生数据路径错误

我在将WatchKit扩展添加到我的应用程序后收到此错误:PBXCpDerivedData/App/Build/Products/Debug-watchsimulator/appwatch.appDerivedData/App/Build/Products/Debug/App.app/Watch/appwatch.appcd/Users/User/Documents/App-watchappexportPATH="/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Deve