草庐IT

class-template

全部标签

c# - 正在注册的类(class)上获取类(class)未注册 80041054

我正在从非托管代码调用CoCreateInstance到已注册的托管类(存在HKEY_CLASSES_ROOT\CLSID{xxxxx-xxxxxx-xxxxxx-xxxxx-xxxxxx-xxxxx}注册表项,并且该文件已从另一个程序正确加载。代码如下:HRESULThRC;CoInitialize(NULL);char*sUTProgID="My.Utilities";CLSIDUTClassID;hRC=CLSIDFromProgID(_CW(sUTProgID),//PointertotheProgID&UTClassID);//PointertotheCLSIDif(S_OK

c++ - 错误 : Use of class template requires template argument list

当我尝试运行我的程序时,此错误显示为“errorC2955:'FOURTEEN':useofclasstemplaterequirestemplateargumentlist”#includeusingnamespacestd;templateclassFOURTEEN{private:Ta[n];public:voidReadData();voidDisplayData();};voidFOURTEEN::ReadData(){for(inti=0;i>a.[i];}voidFOURTEEN::DisplayData(){for(inti=0;i>a.[i]P;//Readdatai

c++ - 前向类声明是否可以在使用位置与 class 关键字互换?

这两个是等价的吗?代码1:classB;classA{public:Bfun1()const;B*m_b;};externvoidmyfun(constB&b);代码2:classA{public:classBfun1()const;classB*m_b;};externvoidmyfun(constclassB&b);或者代码2中呈现的use编程风格是否存在一些问题点? 最佳答案 如果你有一个封闭的范围,这些是不同的。案例一:classB{};namespacetest{classB;//declarestest::BclassA

c++ - 我可以将 `extern template` 放入头文件中吗?

在头文件中放一个外部模板,然后在单元编译文件中显式模板实例化有效吗?例如在g++的编译示例中,这是为了避免nothing的实例化吗?两次?为什么没有人这样写而更喜欢复制externtemplate每个.cpp文件中的行?A.hpp:#ifndefHEADERC_A#defineHEADERC_Atemplatestructnothing{};externtemplatestructnothing;#endifA.cpp:#include"A.hpp"templatestructnothing;ma​​in.cpp:#include"A.hpp"#includeintmain(){not

c++ - 正确的完全特化模板类的前向声明

假设我有以下一堆文件:Generic.h:复杂的模板类#pragmaoncetemplatetypenameC>structGenericMap{Ckey;};Special.h:定义上述模板类的完全专用版本,简化易用性。#pragmaonce#include"Generic.h"#include#includetypedefGenericMapSpecialMap;Client.h:使用SpecialMap并定义前向声明的客户端。#pragmaonceclassSpecialMap;//WrongforwarddeclarationstructClient{Client();Spec

c++ - 如何与 "template using"定义的模板(别名)类成为 friend ?

类B想和每个人成为friendC.我正在努力寻找解决方法。只要我不添加有问题的行,下面是成功编译的完整代码。#includeusingnamespacestd;enumEN{EN1,EN2};templateclassC{public:C(){std::coutclassB{templateusingCT=C;//templatefriendclassCT;//ct;}};intmain(){B::test();return0;}这是我尝试过的(全部失败):-templatefriendclassC;templatefriendclassCT;templatefriendclassCT

c++ - C++ 模板的部分特化 : template parameter not deducible

下面的代码工作正常:templateclassFib{};templateclassFib{};但是下面的代码显示错误为:Error:templateparametersnotdeducibleinpartialspecialization:templateclassFib{};templateclassFib{};你能解释一下这种行为的原因吗? 最佳答案 我相信您只是缺少部分特化的正确语法:templateclassFib{};templateclassFib{};模板上的第一个参数是类型,而第二个只是一个常量值。

c++ - template<class = enable_if_t<...>> 做什么?

我一直在阅读STL文件,以学习格式化代码的更好方法,并学习提高效率的技巧。我一直在阅读线程文件,但我无法弄清楚某些代码的作用。template,thread>::value>>explicitthread(_Fn&&_Fx,_Args&&..._Ax){//constructwith_Fx(_Ax...)...}std::enable_if_t是templateusingenable_if_t=typenameenable_if::type;templatestructenable_if{//typeis_Tyfor_Testusingtype=_Ty;};该代码在thread和str

c++ - 这是对类(Class)友情的恰当运用吗?

在创建Windows父类和子类对话框时,让子类成为父类的友元以访问其私有(private)数据通常是个好主意还是应该使用访问函数? 最佳答案 很少需要friend-通常是当您需要在一个类中重新实现一些深层行为而不重写它以便它们都从单个基类继承或不提供大量访问者时。只有一次我需要它是在ActiveX中重写一个基于openGL的渲染器——当我需要获取大量低级模型数据,但不能(出于非技术原因)重新实现一个通用的ABC时。 关于c++-这是对类(Class)友情的恰当运用吗?,我们在StackO

c++ - 智能指针 : cast between base and derived classes

假设你有这样一个函数:SmartPtrdoSomething(SmartPtra);像这样的类:classA{}classB:publicA{}现在我这样做:SmartPtrfoo=newB();doSomething(foo);现在,我想取回一个SmartPtr来自doSomething的对象.SmartPtrb=doSomething(foo);这可能吗?我需要做什么样的选角?现在,我刚发现一些我认为丑陋的东西:B*b=(B*)doSomething().get()重要说明:我无权访问SmartPtr和doSomething()代码。 最佳答案