草庐IT

inheriting-constructors

全部标签

C++ 2011 : good syntax to initialize an array in a constructor?

这里我有一个示例类:templateclassMyClass{public:MyClass();~MyClass();protected:T_data[SIZE];};templateMyClass::MyClass()://_data()OR_data({})OR_data{}OR...{;}在默认构造函数中将整个数组初始化为0的正确C++2011语法是什么?非常感谢。 最佳答案 统一初始化语法运行良好:MyClass():_data{}{} 关于C++2011:goodsyntaxt

c++ - 视觉 C++ 14 CTP3 : c++11 inheriting constructor bug?

以下代码片段在Clang3.4/3.5(Xcode5/6)下构建完美,但在VisualC++14CTP3下抛出错误:1>------Buildstarted:Project:InheritingConstructor,Configuration:DebugWin32------1>inheritingconstructor.cpp(60):errorC2661:'D::D':nooverloadedfunctiontakes2arguments==========Build:0succeeded,1failed,0up-to-date,0skipped==========代码确实通过尝

c++ - 有没有办法将 "inherit"设为 int 等基类型?

我有几个与此类似的结构:structTime64{int64_tMilliseconds;Time64operator+(constTime64&right){returnTime64(Milliseconds+right.Milliseconds);}...blahblahallthearithmeticoperatorsforcalculatingwithTime64andint64_twhichisassumedtorepresentmillisecondsstd::stringParse(){fancytextoutput}}现在我需要添加更多它们。本质上它们只是对任何基类的解

c++ - 继承构造函数仅部分起作用

我有下面的类(class),写成这样,无论typedef是什么,它都能完全工作:classA{protected:typedefucharmDataType;std::vectormData;uint32mWidth;uint32mHeight;friendclassC;public:A();A(void*data,uint32width,uint32height,size_tdataSize);A(constA&other);A(A&&other);A&operator=(constA&other);A&operator=(A&&other)=delete;~A();}我想创建一个子

c++ - 在模板派生类中继承具有类型别名的构造函数

这个问题在这里已经有了答案:A'using'statementcompileswithg++,failscompilationwithclang(2个答案)关闭4年前。请看下面的代码:structbase{};templatestructderived:T{usingbase_type=T;usingbase_type::T;};intmain(){derivedx;}GCC接受此代码,但Clang和MSVC拒绝它。谁是对的,为什么?

c++ - "virtual base class in the case of multilevel inheritance"有意义吗

考虑以下显示多级继承的示例代码:案例1:这里类derived1是通过虚拟继承从类base派生的,类derived2是从类派生的直接类derived1。classbase{};classderived1:virtualpublicbase{};classderived2:publicderived1{};Case2:与Case1相同,只是不涉及虚拟继承classbase{};classderived1:publicbase//novirtualinheritance{};classderived2:publicderived1{};假设我在这两种情况下都创建了derived2类的对象。C

c++ - std::runtime_error 子类的 "call to deleted constructor of"编译器错误

我从std::runtime_error派生了一个异常类,以便添加对异常流的支持。我收到一个奇怪的编译器错误输出,我不确定如何解决?clang++-std=c++11-stdlib=libc++-g-Wall-I../-I/usr/local/includeMain.cpp-cMain.cpp:43:19:error:calltodeletedconstructorof'EarthException'throwEarthException(__FILE__,__LINE__)^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~../EarthExce

c++ - 最烦人的解析 : why doesn't `g( ( f() ) );` call `f` 's default constructor and pass the result to `g` 's ctor that takes a `f` ?

这不是Mostvexingparse:whydoesn'tAa(());work?的拷贝,它基于Aa());形式的解析,其OP认为可以使用额外的集合默认构造一个A对象括号。相比之下,我的问题是关于2个类,f和g,其中f具有默认构造函数,而g的构造函数采用f。我想用一个临时的f参数调用g的构造函数,而不使用统一的初始化语法。g的构造函数中有一个std::cout语句,因此缺少输出表示函数声明而不是g对象实例化。我在注释中用3个数字注释了示例代码。#1和#2编译时#3被注释掉,反之亦然:#includestructf{};structg{g(f){std::cout#1:我认为#1声明了一

c++ - 两阶段查找 : is it possible to easily mix inheritence and templates

简介:C++标准区分依赖模板参数的符号名称和不依赖模板参数的名称,这称为两阶段名称查找(参见here)。定义模板时,会尽快解析非相关名称。另一方面,从属名称仅在模板实例化时解析。示例:templatestructBase{typedefTtype;staticconstintn=3;virtualintf()=0;intf(intx){returnx*2;}};//doesn'tcompile!templatestructDerived:Base{typefield;//Thecompilerdoesn'tknowBase::typeyet!intf(){returnn;}//thec

c++ - 复制初始化: why move or copy constructor was not called even if copy-elision is turned off?

我的问题不同,因为我可能“知道”复制省略。我正在学习复制初始化。但是,以下代码让我感到困惑,因为我已经使用-fno-elide-contructors-O0选项关闭了复制省略。#includeusingnamespacestd;classtest{public:test(inta_,intb_):a{a_},b{b_}{}test(consttest&other){cout我首先使用命令构建:g++-std=c++11-fno-elide-constructors-O0main.cpp-omain得到如下结果:**showelideconstructors**moveconstruct