草庐IT

TYPE_CLASS_DATETIME

全部标签

c++ - 以某种方式在列表中注册我的类(class)

我希望能够在std::map或vector中注册我的类,暂时不要考虑重复等问题,但我不想在类构造函数调用或类的任何内部函数中注册它,而是在类之外以某种方式进行注册,因此即使我从未实例化它,我也能够知道它存在。例子://Somehow,fromoutsidethemyclass,inascopethatwillbecalled//inthebeginingoftheproccess,add"MyClass1"toa//listsoitcanbeinstanciatedlaterclassMyClass1{}然后我会为它制作一个#define,或者如果可以的话,制作一个模板。我不知道我是否

c++ - 类设计建议 : extending a class and code reuse

这个问题的要点是关于扩展一个类,最大限度地减少将所有内容打包到一个类中,以及最大限度地重用代码。阅读此问题后,请随时编辑标题或描述以使其更简洁。虽然帖子看起来很长,但我只是想通过使用大量示例来做到全面。假设我有一个类:classUsedByManyPeople{//...hasmanyfields};顾名思义,这个类被很多开发者使用。我必须向此类添加2个功能:将UsedByManyPeople转换为SomeOtherType的convert()返回字符串的getFileName()它们都是针对我部门的需求。第一次尝试解决方案起初我想简单地向UsedByManyPeople添加2个新方法

c++ - 错误 C2504 : 'BASECLASS' : base class undefined

我查看了一个与此类似的帖子,但链接不同,问题从未得到解决。我的问题是,出于某种原因,链接器期望有一个基类的定义,但基类只是一个接口(interface)。以下是完整的错误c:\users\numerical25\desktop\introtodirectx\godfiles\gxrendermanager\gxrendermanager\gxrendermanager\gxdx.h(2):errorC2504:'GXRenderer':baseclassundefined下面是显示标题如何相互链接的代码GXRenderManager.h#ifndefGXRM#defineGXRM#in

c++ - 是否有可能调用一个父类(super class)的构造函数,两个类远离 C++ 中的当前类

我有三个继承如下的类:Class_AClass_B:publicClass_AClass_C:publicClass_BClass_A包含一个构造函数:public:Class_A(constchar*name,intkind);Class_B不包含该构造函数。在Class_C中,我希望调用Class_A的构造函数。像这样的东西:Class_C(constchar*name,intkind):Class_A::Class_A(name,kind){}问题是我无法向Class_B添加中间构造函数,因为Class_B是生成的代码,每次我makeclean时都会重新生成。所以我无法对Clas

c++ - 前向声明的类型和 "non-class type as already been declared as a class type"

我对以下代码有疑问:templatevoidfoo(structbar&b);structbar{};intmain(){}它在GCC上编译成功,但在MSVC(2008)上编译失败并出现以下错误:C2990:“bar”:已声明为类类型的非类类型是代码错误还是MSVC中的错误?如果我在模板定义之前添加structbar;就可以了。 最佳答案 我们有我们的赢家:https://connect.microsoft.com/VisualStudio/feedback/details/668430/forward-declared-type-

c++ - 错误 C2678 : binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion)

我正在尝试对每个元素中包含一个int和一个字符串的vector进行排序。它是一个称为vector食谱的类类型的vector。出现上述错误,这是我的代码:在我的Recipe.h文件中structRecipe{public:stringget_cname()const{returnchef_name;}private:intrecipe_id;stringchef_name;在我的Menu.cpp文件中voidMenu::show()const{sort(recipes.begin(),recipes.end(),Sort_by_cname());}在我的Menu.h文件中#include

c++ - std::is_convertible 用于 type_info

在C++11中,可以通过usingstd::is_convertible确定类型A的变量是否可以隐式转换为类型B.如果你真的知道类型A和B,这很有效,但我只有type_infos。所以我正在寻找的是这样的功能:boolmyIsConvertible(consttype_info&from,consttype_info&to);是否可以在C++中实现类似的东西?如果是,怎么办? 最佳答案 在可移植的C++中做你想做的事是不可能的。可能如果您将自己限制在给定的平台上,则有可能获得部分答案。例如那些遵守ItaniumABI的平台将实现此功

c++ - CRTP + 特征类 : "no type named..."

我尝试使用模板化类实现CRTP,但在使用以下示例代码时出现错误:#includetemplateclassTraits{public:typedeftypenameT::typetype;//'staticconstunsignedintm_const=T::m_const;staticconstunsignedintn_const=T::n_const;staticconstunsignedintsize_const=T::m_const*T::n_const;};templateclassCrtp{public:typedeftypenameTraits::typecrtp_typ

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct

c++ - 标准 :forward inside a template class

templateclassBlockingQueue{std::queuecontainer_;templatevoidpush(U&&value){static_assert(std::is_same::type>::value,"Can'tcallpushwithoutthesameparameterastemplateparameter'sclass");container_.push(std::forward(value));}};我希望BlockingQueue::push方法能够处理T类型对象的右值和左值引用,以将其转发到std::queue::push正确的版本。是像上面