草庐IT

C++ 不同类型模板化类的显式模板化函数实例化

我正在尝试在T类型的模板化类中显式实例化U类型的模板化函数。我下面的代码生成了一个警告,并且链接器没有找到ReinterpretAs()的显式实例化。任何人都可以发现错误或建议如何执行此操作吗?我正在使用VC++2010。templateclassMatrix{public:templateMatrixReinterpretAs()const;};templatetemplateMatrixMatrix::ReinterpretAs()const{Matrixm;//...returnm;}//Explicitinstantiation.templateclassMatrix;temp

c++ - 将 MFC 宏与模板一起使用

是否可以从CDialog等MFC类派生并使用C++模板类。我已经尝试过,但实现失败于用于消息路由的MFC宏。例如;templateclassCMyDialogT:publicCDialog{public:CMyDialogT(CMyContainerT*pData,CWnd*pParent=NULL);CMyContainerT*m_pData;//Generatedmessagemapfunctions//{{AFX_MSG(CMyDialogT)afx_msgvoidOnUpdateMyControl();//}}AFX_MSGDECLARE_MESSAGE_MAP()};temp

c++ - 模板类 C++ - 排除某些类型

我最近创建了一个工作正常的模板类。现在我想使用“constint”(例如),但是动态绑定(bind)是被禁止的。是否有可能排除constint类型?这是我的课;编译器将为第二个构造函数丢弃错误。我已经看到了,但我只是不知道如何以正确的方式和想法修改它?templateclassVector2D{public:TX;TY;Vector2D(){X=0;Y=0;};Vector2D(Tx,Ty){X=x;Y=y;};} 最佳答案 使用成员初始化列表:templateclassVector2D{public:TX;TY;Vector2D(

c++ - 具有引用参数的重载函数模板

templatevoidf(T&){}templatevoidf(T&&){}intmain(){intx;f(x);//ambiguous}为什么这个调用不明确?第一个模板特化是f(int&),第二个是f(int&).由于参数相同,根据偏序规则更特殊的函数模板更好。然后根据标准14.8.2.4/9If,foragiventype,deductionsucceedsinbothdirections(i.e.,thetypesareidenticalafterthetransformationsabove)andbothPandAwerereferencetypes(beforebein

c++ - 通过 visual studio 2010 项目模板设置 cocos2d-x 应用程序

我正在尝试使用Cocos2D-x在Windows7上设置应用程序。我关注了这个tutorial.我做了以下事情:构建运行Build-win32.bat脚本的库。有效。安装了VS2010项目模板。有效。成功运行所有测试程序。通过安装的模板创建了一个新的cocos2D-x项目。作品当我编译HelloWorld应用程序时出现以下错误:errorC1083:impossibletoopeninclusionfile'CCstdC.h'NosuchfileordirectoryerrorC1083:impossibletoopeninclusionfile'cocos2d.h'Nosuchfil

c++ - 如何在不创建空类的情况下避免专门化 "big"模板类?

鉴于以下情况:templateclassTuple{private:T0v0;T1v1;T2v2;T3v3;T4v4;public:voidf(){cout我想创建一个只有两个int的部分类-s,那么我必须像这样专门化:classNullType{};//createanemptyclasstemplateclassTuple{private:T0v0;T1v1;public:voidfunc(){cout但是这个实现需要我做:Tupleb;所以这很丑:)是否有另一种方法可以在不定义另一个(空)类的情况下实现部分特化,这样我就可以做到:Tupleb1;? 最

c++ - 字符串作为模板参数

虽然C++标准不允许使用字符串文字作为模板参数,但允许这样的事情:ISO/IEC14882:201114.3.2Templatenon-typearguments[temp.arg.nontype]2[Note:Astringliteral(2.14.5)doesnotsatisfytherequirementsofanyofthesecategoriesandthusisnotanacceptabletemplate-argument.[Example:templateclassX{/.../};Xx1;//error:stringliteralastemplate-argument

c++ - 更大类的单个方法的部分模板特化

我有以下类(class);templateclassBaumWelch{//lotsofstuffconstTransitionMatrixTemplaterandomA(){//....}}现在我想专门针对N=1的方法randomA。我该怎么做?我试着回答这个问题:Templatespecializationofasinglemethodfromatemplatedclass,但它似乎不适用于部分特化。本题:C++partialmethodspecialization似乎更相关,但它建议对整个类(class)进行特化(对我来说这相当大)。是否可以特化整个类,但实际上只特化这个方法?

c++ - 模板类的返回类型未知

我创建了一个矩阵类,想要添加两个不同数据类型的矩阵。像int和double返回类型的矩阵应该是double。我怎样才能做到这一点???这是我的代码templateclassMatrix{..................templateMatrixoperator+(Matrix&B){if((typeid(a).before(typeid(B.a))))Matrixres(1,1);elseMatrixres(1,1);}这里的“东西”应该是什么???另外应该怎么做才能在ifelse语句之外使用“res”??? 最佳答案 您可以

c++ 模板参数列表中参数 1 的类型/值不匹配

#includeusingnamespacestd;templateclasspeople{public:virtualvoidinsert(Titem)=0;virtualTshow(Tinfo)=0;};templateclassname{private:Tfname;Tlname;public:name(Tfirst,Tlast);//booloperator==(name&p1,name&p2)};templatename::name(Tfirst,Tlast){fname=first;lname=last;}templateclassperson:publicpeople{p