草庐IT

get_template_args_count

全部标签

c++ - 嵌套类声明 : template vs non-template outer class

我有一个C++模板类,里面有一个嵌套类,比如:templateclassOuter_t{public:classInner;Inneri;};templateclassOuter_t::Inner{public:floatx;};intmain(){Outer_to_t;//3oranyarbitraryinto_t.i.x=1.0;return0;}编译没有任何问题。然而,一旦我声明了一个类似的非模板类,就像这样:classOuter_1{public:classInner;Inneri;};classOuter_1::Inner{public:floatx;};intmain(){

c++ - 为枚举索引数组重载 std::get

我发现拥有一个基本上像std::array但由一些枚举的值索引的类相当方便。我想不难想象如何实现它,假设它有一个像这样的签名:classenum_array另一方面,在尝试实现所有标准的std::array相关函数时,我注意到为此类编写重载的std::get函数模板没那么简单。首先,我认为这个std::get具有上述枚举的值作为模板参数是很自然的,因此出现了大多数问题:1)如果我想在类外定义这样的函数,我必须做类似的事情:namespacestd{templateEnumT&get(enum_array&val)但问题是在指定第一个模板参数时EnumT仍然是未知的,所以这个模板实际上是

c++ - 在 C++ 中定义虚拟 get 和 set 函数被认为是一种好的做法吗?

如果我有一个简单的2级类层次结构,例如这个://level1classSpare_Part{private:stringname;doubleprice;public:Spare_Part();stringgetName(){returnname;}doublegetPrice(){returnprice;}virtualintgetQuantity(){return-1;};//mayalsodefineitaspurevirtual};//level2classOn_hand:publicSpare_Part{private:intquantity;stringlocation;p

c++ - 将临时变量写入 Json : I get\u0000

我面临一个奇怪的问题:当我尝试在for循环中添加一个Json变量时,它没有正确写入输出文件,而它在循环外运行良好(rapidJsonv0.11)。编辑:循环不是问题,但即使只有括号也会出现错误这是我的代码示例:rapidjson::Documentoutput;output.SetObject();rapidjson::Document::AllocatorType&allocator=output.GetAllocator();{std::strings1("test");output.AddMember("test_field",s1.c_str(),allocator);}std

c++ - 错误 : 'Failed to specialize function template' C2893 'std::invoke'

我正在VisualStudio2013中编写MFC程序,但我不断收到以下两个错误错误C2893无法特化函数模板'unknown-typestd::invoke(_Callable&&,_Types&&...)'和错误C2672“std::invoke”:找不到匹配的重载函数错误与文件xthread第238行有关我是c++/MFC的新手,我正在尝试编写一个将在后台运行到系统时间的函数。这是我使用的代码:voidtask1(ExperimentTab&dlg){while(true){CStringshowtime=CTime::GetCurrentTime().Format("%H:%M

为什么我们不在渲染方法中编写axios.get(blabla)?

我们为什么不写axios.get('https://rallycoding.herokuapp.com/api/music_albums').then(response=>this.setState({albums:response.data}));在-的里面render方法,我们必须把它放在componentWillMount?如果我们把它放在开始的开始render方法?我把它放在render并得到相同的结果,但教程说应该在componentWillMount.看答案通常,两者之间的区别将在多少次您想提出这个请求吗?如果您只想在组件第一次安装时才发生,您将使用ComponentWillMou

c++ - va_list 还在 C++ 中使用吗?还是鼓励使用 template<typename...T>?

在C中,定义可变长度参数的唯一方法是使用省略号声明其原型(prototype)并使用va_list、va_start、va_arg,va_end来提取它们。就像printf系列和scanf系列一样。在C++11中,引入了如下新方法。templatevoidfunc(Targ,MoreT...args){//Dosomestufffunc(args);}每种方法的优点和缺点是什么?在C++中是不鼓励使用还是鼓励使用它们中的任何一个? 最佳答案 在C++中强烈不鼓励使用C风格的可变参数函数。风格各不相同,但编写这些类型的函数会让您在某些

c++ - 为什么我不能将 && 添加到 Ret (Args...) &?

当我尝试像这样编写自己的decay_t时:#includetemplatestructauto_decay{autooperator()()noexcept{returnstd::declval();}};templateusingdecay_t=decltype((decl_as>())());并使用以下方法对其进行测试:#includeintmain(){static_assert(is_same,int(*)()>{}());}我遇到了以下错误:Infileincludedfromtest_decay.cc:1:Infileincludedfrom./../src/decay.h

c++ - Curiously Recurring Template Pattern (CRTP) 是正确的解决方案吗?

场景考虑一个Logger类,它有一个为标准C++类型重载的成员函数write(),还有一些方便的函数模板,比如writeLine()内部调用write():classLogger{public:voidwrite(intx){...}voidwrite(doublex){...}...templatevoidwriteLine(Tx){write(x);...}...};进一步考虑一个子类FooLogger,它为特定于域的类型添加了额外的write()重载(我们称其中两个为FooType1和FooType2):classFooLogger:publicLogger{public:usi

c++ - 错误 : use of deleted function for overloaded template

我正在尝试模板特化,但无法确定为什么charconst*const无法在下面解析(尽管是有效类型)的原因。templateBfoo(A)=delete;templatevoidfoo(char*){}templatevoidfoo(charconst*const){}intmain(){{//typesOKcharconst*consta=nullptr;char*b=nullptr;}char*data;foo(data);//OKfoo(data);//ERRORreturn0;}错误error:useofdeletedfunction‘Bfoo(A)[withA=constcha