草庐IT

inheritence

全部标签

c++ - 模板类 : static members not inherited

这个问题在这里已经有了答案:Whydoesn'taderivedtemplateclasshaveaccesstoabasetemplateclass'identifiers?(4个答案)关闭7年前。下面的代码templatestructBase{staticconstinta=c+5;};templatestructDerived:Base{staticconstintb=a+5;};...编译失败因为awasnotdeclaredinthisscope.明确指定Base::a有效,但从逻辑上讲这不是必需的,因为我们是从Base派生的.这是预期的行为(以及为什么)还是我遗漏了什么?

c++ - 取消 pthread_cond_wait() 挂起与 PRIO_INHERIT 互斥锁

2012年4月10日更新:Fixedbylibcpatch我在pthread_cond_wait中取消线程时遇到问题,将互斥锁与PTHREAD_PRIO_INHERIT一起使用属性集。不过,这只发生在某些平台上。以下最小示例演示了这一点:(使用g++.cpp-lpthread编译)#include#includepthread_mutex_tmutex;pthread_cond_tcond;voidclean(void*arg){std::cout每次我运行它,main()卡在pthread_join().gdb回溯显示如下:Thread2(Thread0xb7d15b70(LWP25

c++ - 海湾合作委员会 : C++11 inline object initialization (using "this") does not work when there is a virtual inheritance in hierarchy

当在初始化中使用此指针并且在层次结构中存在虚拟继承时,C++11内联对象初始化不起作用(在GCC中)。这可能是GCC的错误吗(因为它在CLang中工作)?还是C++11标准本身的差距?示例(可以在here中尝试),当使用GCC编译以下代码时:FieldIndexm_inB{"inB",this};不会被执行。但它会在使用CLang编译时执行。变通方法:从FieldIndexContainer派生A作为虚拟#include#include#includeusingnamespacestd;classFieldIndexContainer{public:classFieldIndex{pu

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++ - "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++ - 两阶段查找 : 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++ - "Inheriting"具有可变模板函数的类

我想编写一个可以操作不同类型数据库(例如sqlite、postgres等)的数据库包装器,因此无论用户实际使用什么数据库,他们编写的代码都不会改变。在我看来,这需要一个抽象基类,例如:classdatabase{public:virtualboolquery(conststd::string&q)=0;//Otherstuff};classsqlite:publicdatabase{public:boolquery(conststd::string&q){//Implementation}};这看起来不错,但我正在使用可变参数模板来转义查询中的参数(我真的很喜欢这个想法,所以我想坚持下

c++ - 转发声明 : templates and inheritance

在编写框架时遇到以下问题:我有classA和classB派生自classA。classA有一个返回B*的函数。当然,这并不难:#includeusingnamespacestd;classB;//forwarddeclarationclassA{public:B*ReturnSomeData();};classB:publicA{};//Implementation:B*A::ReturnSomeData(){returnnewB;//doesn'tmatterhowthefunctionmakespointer}intmain(){Asth;cout但是我不得不使用像这里这样的模板:

c# - 如何在 C# 中使用 Private Inheritance aka C++ 以及为什么它不存在于 C# 中

我知道C++支持私有(private)继承,C#只支持公有继承。我还看到一篇文章说私有(private)继承通常定义类之间的HAS-A关系和某种聚合关系。编辑:私有(private)继承的C++代码:“Carhas-aEngine”关系也可以用私有(private)继承来表达:classEngine{public:Engine(intnumCylinders);voidstart();//StartsthisEngine};classCar:privateEngine{//Carhas-aEnginepublic:Car():Engine(8){}//InitializesthisCa