草庐IT

main_template

全部标签

c++ - int main(void) 在 C++ 中有效吗?

C++标准列出了main允许的形式。它没有将intmain(void)列为允许的形式。但是,它通常指出Theparameterlist(void)isequivalenttotheemptyparameterlistintmain(void)是一种允许的形式吗? 最佳答案 来自N3936标准草案:3.6Startandtermination3.6.1Mainfunction2Animplementationshallnotpredefinethemainfunction.Thisfunctionshallnotbeoverloade

C++ 模板部分特化 : Why cant I match the last type in variadic-template?

我尝试编写一个IsLast类型特征来检查给定类型是否是std::tuple中的最后一个类型,但下面的代码无法编译。我知道如何绕过它,但我很好奇为什么编译器不喜欢它。我想一定有一些我不知道的关于可变参数模板特化的规则。代码位于:https://godbolt.org/g/nXdodx错误信息:error:implicitinstantiationofundefinedtemplate'IsLast,int>,int>'还有关于特化声明的警告:warning:classtemplatepartialspecializationcontainstemplateparametersthatca

c++ - 将具有默认值的数组作为参数传递给 int main()

我很难将数组作为参数传递给具有默认值的intmain()。例如:intmain(inta){}效果很好。同样intmain(inta=1){}传递intmain()一个数组也能很好地工作:intmain(inta[3])但是,将这两个概念结合起来似乎是错误的:intmain(inta[1]={0,1})经过大量的googleing,我还没有找到解决方案。请帮助我吧,你是我唯一的希望!编辑这样做的目的,简而言之,是让我的代码尽可能少行,以应对我的教授最近发布的挑战(不是为了加分-只是为了学习)。作业是创建一个递归的“圣诞节12天”程序这是我当前的程序#include#includevoi

c++ - 警告 : specialization of template in different namespace

通过以下代码我得到了警告:warning:specializationof‘templatestructstd::iterator_traits’indifferentnamespace[-fpermissive]templateclassstd::iterator_traits{public:typedefWorddifference_type;typedefWordvalue_type;typedefToken_ptrpointer;typedefWord&reference;typedefstd::bidirectional_iterator_tagiterator_catego

c++ - 我们什么时候需要 .template 结构

我做了如下程序#include#includetemplatestructClass{templatevoiddisplay(){std::coutvoidfunc(Classk){k.display();}intmain(){Classd;func(d);}上面的程序没有编译因为display()是一个模板成员函数,所以.template的资格之前display()必须完成。我说得对吗?但是当我制作下面的程序时#include#includetemplateclassmyClass{Tdummy;/*******/public:templatevoidfunc(myClassobj)

c++ - 将 Curiously Recurring Template Pattern (CRTP) 与其他类型参数一起使用

我尝试使用CuriouslyRecurringTemplatePattern(CRTP)并提供额外的类型参数:templateclassBase{Int*i;Float*f;};...classA:publicBase{};这可能是一个错误,更合适的父类(superclass)是Base--尽管这种参数顺序不匹配不是那么明显。如果我可以在typedef中使用名称参数的含义,这个错误会更容易看到:templateclassBase{typenameSubclass::Int_t*i;//error:invaliduseofincompletetype‘classA’typenameSub

c++ - 在项目中使用 QT 单元测试 - 冲突的 main(...) 函数

我踏上了使用单元测试开发我的应用程序的崇高道路,但事实证明这是一条陡峭而崎岖的道路。我正在用Qt开发一个应用程序,因此想到了他们的QTestLib框架。现在,我了解了如何进行单元测试,但我似乎无法弄清楚如何将单元测试合并到项目中。假设我有一个控制台应用程序,它只有一个main.cpp以及一个cpp和h文件,用于我想开发的类,比如MyClass。我想正确的做法是创建一个相应的测试类MyClassTest及其h和cpp文件。但是我应该把它放在同一个项目中吗?或者更确切地说,为单元测试创​​建一个单独的项目,该项目将可以访问“主”项目中的文件(不确定我该怎么做)?如果主应用程序和测试都在同一

c++ - "template"不需要关键字? [gcc/clang/Comeau 错误?]

这是测试代码templatevoidf(){Tt;t.f(0);//compilesevenwithoutthe"template"keyword,whatamImissing?}classabc{public:templatevoidf(int){}};intmain(){f();}我正在使用g++4.4.6。谢谢P.S:我已经大大编辑了我的问题。请不要介意。编辑:我向EDG的人问了这个问题,这是MikeHerrick不得不说的Wedodiagnosethisasanerrorin--strictmodeaswellasanymodethatenablesdependentnamel

c++ - G++ 编译器错误或错误代码? : "template definition of non-template"

作为大型程序的特征类的一部分,我尝试创建一个静态类变量,该变量可能具有不同的值,具体取决于实例化封闭类模板的类型。我已经简化了相关代码以生成我正在谈论的内容的简单示例:#include#include#includetemplatestructFoo;templatestructFoo::value>::type>{staticstd::stringmessage;};templatestructFoo::value>::type>{staticstd::stringmessage;};templatestd::stringFoo::message;对于GCC4.6,这会产生一个编译器

c++ - C++1 7's deduced ` auto` 非类型 `template` 参数是否可以使用显式非类型参数模式匹配模板?

考虑这个例子(alsoavailableonwandbox):templateclass>voidtest(){}templatestructX{};正在尝试实例化test()在clang++4.0(trunk)导致编译错误:error:nomatchingfunctionforcallto'test'test();^~~~~~~note:candidatetemplateignored:invalidexplicitly-specifiedargumentfor1sttemplateparametervoidtest(){}我最初的假设/直觉是test可用于匹配任何template具