草庐IT

claim_template

全部标签

c++ - Clang claims that `member reference base type ' X' is not a structure or union`,但 X 是具有推导参数的结构模板

考虑以下代码:templatestructX{X(T){}voidfoo(){}};templatestructY{intobject=0;voidbar(){X(object).foo();}};Liveongcc.godbold.orgGCC8.2编译它,而Clang7吐出以下错误::13:18:error:memberreferencebasetype'X'isnotastructureorunionX(object).foo();~~~~~~~~~^~~~这对我来说像是一个错误。条件非常具体:如果任一结构不是模板,或者object不是成员变量,或者不涉及CTAD(类模板参数推导

c++ - 默认模板参数 : Why does the compiler complain about not specifying template argument?

我有这个代码:structA{};templatestructB{voidfoo(){}};Bb;//Error:missingtemplateargumentsbefore'b'//Error:expected';'before'b'//Moreerrorsb.foo()如果我将foo()作为具有相同模板“签名”的模板函数,编译器不会提示没有指定模板参数:structA{};structB{templatevoidfoo(){}};Bb;//OKb.foo()那么为什么我需要为带有默认参数的模板类指定参数,而不是为模板函数指定参数呢?我是否遗漏了一些微妙之处?原因肯定是因为模板参数推

c++ - "Invalid template argument"错误在 Visual Studio 但不是 GCC

假设你有代码templateclassBaseType>classEST16:publicBaseType{public:EST16(doubled){}};templateclassSCEST{Ty;};typedefEST16EST16_SC;classChild:publicEST16_SC{public:Child():EST16_SC(1.0){}};classNotWorkingChild:publicEST16{public:NotWorkingChild():EST16(1.0){}};TEST(TemplateTest,TestInstantiate){Childch

c++ - `class template Example<int>;` 语句对 C++11 意味着什么?

有人提到我"ExplicitTemplateInstantiation"在cplusplus.com,它给出了以下示例:templateclassExample{public:Example(Ttest){_data=test;}voidsetTest(Ttest){_data=T;}private:T_data;};classtemplateExample;classtemplateExample;classtemplateExample;除了在我看来是一个遗漏错误之外,试图将类型分配给成员变量--_data=T而不是我认为应该是_data=test--我不明白的是最后3行究竟声明或

c++ - 错误 : ‘list’ is not a member of ‘std’ and error: template argument 2 is invalid

我正在尝试编译我的头文件,但我遇到了我无法弄清楚的错误。我想创建一个包含3个映射的结构:-从单个单词映射到计数-从词对映射到计数-从单个单词映射到后续单词列表我的头文件中的代码:#include#include#include#include#include#include#include#includetypedefstruct{std::mapfirstCounts;std::mappairCounts;std::map>follows;//Youcanuseaniteratortoretrievethevaluesstoredinthelist.}LanguageModel;我得

c++ - 模板特化是否需要 template<> 语法?

我有一个类似这样的访客类:structVisitor{templatevoidoperator()(Tt){...}voidoperator()(boolb){...}};很明显,operator()(boolb)旨在成为上述模板函数的特化。但是,它没有template语法,我以前经常看到它,将其声明为模板特化。但它确实可以编译。这样安全吗?这是正确的吗? 最佳答案 您的代码不是模板特化,而是非模板函数。那里有一些差异。非模板化operator()将优先于模板化版本(对于精确匹配,但类型转换不会在那里发生)但您仍然可以强制调用模板化

C++ : Vector of template class

我有一个名为Cell的模板类,如下所示:-templateclassCell{stringheader,Tdata;}现在我想要另一个名为Row的类。Row将有一个名为Cells的vector,这样我就可以将Cell和Cell类型的元素添加到该vector中。可能吗?如果是这样,我该怎么做?提前致谢。 最佳答案 根据您提供的额外详细信息,前两个答案将无效。您需要的是一种称为单元格变体的类型,然后您可以获得这些类型的vector。例如:-enumCellType{Int,Float,//etc};classCell{CellTypet

c++ - variadic template template中的Variadic template推导

我不确定这个标题是否有意义,但这个例子实际上很简单://Aconverterstructwithagenericconstructor.templateclassTT>structconverter{templateconverter(constTT&);};//Afewclasstemplates.templatestructfoo{};templatestructfoo2{};templatestructfoo_variadic{};templatestructfoo_variadic2{};intmain(){//Allthesecompile.converter(foo{});

c++ - "class template"与 "template class"

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:Whatisthedifferencebetweenatemplateclassandaclasstemplate?我见过几个C++大师因为调用类似的东西而抨击人们templateclassSomeClass{//...};模板类而不是类模板。(请注意,这不是什么大错特错,但表明某人不是经验丰富的C++程序员)是的,正确的词是“类模板”——因为它是用于生成类的模板。但我不明白为什么在典型的对话中区分很重要。没有人听/读你写的东西会明白你所说的是什么意思。在标准或其他方面是否有特定使用“模板类”一词的情况,这使

c++ - 铿锵错误 : non-type template argument refers to function that does not have linkage -- bug?

我有一些非常简单的(C++11)代码,最新的clang(version3.4trunk187493)无法编译,但GCC编译正常。代码(下面)实例化函数模板foo使用局部函数类型Bar然后尝试将其地址用作类模板Func的非类型模板参数:templatestructFunc{};templateexterninlinevoidfoo(){usingFoo=Func>;}intmain(){structBar{};//function-localtypefoo();return0;}clang发出以下错误:error:non-typetemplateargumentreferstofunct