草庐IT

MAKE_TEMPLATE

全部标签

c++ - g++ 可变参数模板。简单示例代码无法编译,提示 'Not a template'

我正在探索这个陌生的领域,并想尝试来自DannyKalev'stutorialonthematter的一个简单示例.代码非常简单:templatestructCount{staticconstintvalue=0;};templatestructCount//partialspecialization{staticconstintvalue=1+Count::value;};但是gcc4.4.7甚至4.7.0提示(尽管-std=c++0x-std=gnu++0x标志):/src/tests/VTemplates.h:12:8:error:'Count'isnotatemplate/sr

c++ - 错误 C2899 : typename cannot be used outside a template declaration

我正在MSV2010中尝试以下内容namespacestatismo{templatestructRepresenterTraits,3u>>{typedefitk::Image,3u>VectorImageType;typedefVectorImageType::PointerDatasetPointerType;typedefVectorImageType::PointerDatasetConstPointerType;typedeftypenameVectorImageType::PointTypePointType;typedeftypenameVectorImageType:

c++ - 将 make_shared 与可变参数模板绑定(bind)

我正在尝试编写以下工厂类,但找不到正确的语法:templateclassFactory{public:Factory(TArgs...args){creator_=std::bind(&std::make_shared,args...);//^^^someerroraroundhere}std::shared_ptrCreate()const{returncreator_();}private:std::function()>creator_;};这就是我使用工厂的方式:classFoo{public:Foo(boolvalue){}};classBar{public:Bar(cons

【论文阅读笔记】Make-A-Character: High Quality Text-to-3D Character Generation within Minutes

【论文阅读笔记】分钟级别的高质量文本到3D角色生成AbstractIntroductionMethodLL/VM解析人脸面部属性并生成根据密集地标重建face/head形状几何生成纹理生成纹理提取漫反射反照率(DiffusionAlbedo)估计纹理矫正和补全头发生成(牛了)资产匹配实验未来工作paperhttps://arxiv.org/abs/2312.15430Demohttps://huggingface.co/spaces/Human3DAIGC/Make-A-CharacterCodehttps://github.com/Human3DAIGC/Make-A-CharacterPr

c++ - std::make_shared 三元返回不编译

我正在使用VisualStudio2010并拥有用于创建抽象基类的两个实现之一的工厂。工厂Create方法采用bool标志并返回shared_ptr中的两个impls之一。使用if语句对我来说效果很好,但是当我尝试使用带有make_shared调用的三元时编译器会报错。classBase{public:Base(){};};classFoo:publicBase{public:Foo(){};};classBar:publicBase{public:Bar(){};};classFactory{public:staticstd::shared_ptrCreate(boolisFoo){

c++ - std::make_pair、c++11 和显式模板参数

这个问题在这里已经有了答案:C++11make_pairwithspecifiedtemplateparametersdoesn'tcompile(1个回答)关闭7年前。重新编辑:首先,这只是一个好奇的问题,我知道,std::pair或许多其他解决方案可以根除这个问题。你能告诉我,下面这个问题的背后究竟是什么吗?此代码是一个在c++03上运行但在c++11上失败的简单示例。std::pairgetsth(int*param){returnstd::make_pair(param,0);}intmain(intargc,char*argv[]){int*a=newint(1);std::

C++ : friend declaration ‘declares a non-template function

我在重载时遇到问题流运算符(operator),我找不到解决方案:templateclassNVector{inlinefriendstd::ostream&operator&rhs);};templateinlinestd::ostream&NVector::operator&rhs){/*SOMETHING*/returnlhs;};它产生以下错误信息:warning:frienddeclaration‘std::ostream&operatorerror:‘std::ostream&NVector::operator如何解决这个问题?非常感谢。 最佳答

c++ - 如何在 Visual Studio 中解决 make_shared 的 10 个限制

在一些旧代码上使用C++10的新功能时,我遇到了无法调用带有12个参数的make_shared的问题。我记得Microsoft的STL谈到他们如何为make_shared使用仿真,并且10是最大值。显然仅仅为此重构代码是不可能的,所以基本上我的问题是-有没有办法在VS2010中为make_shared获取超过10个参数。 最佳答案 make_shared(1,2,3,4,5,6,7,8,9,10,11,12);可以替换为shared_ptr(newfoobar(1,2,3,4,5,6,7,8,9,10,11,12));在C++11中

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]

C++ 如何使 template<T>f() 为整数 T 返回 -1,为指针类型返回 nullptr

我需要完成以下任务:templatef(){:return{-1ifTisofintegraltype,elsenullptr}}在我的特定用例中,T可以是四种类型之一:intPy_ssize_t//ssize_tPy_hash_t//ssize_tPyObject*//PyObjectissomeCstruct这是我迄今为止最好的解决方案:templateTtest(typenameenable_if::value,void*>::type=nullptr){return-1;}templateTtest(typenameenable_if::value,void*>::type=n