草庐IT

non-main

全部标签

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

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

c++ - 我可以在类定义中放置 "non-static blocks"代码吗?

C++中有非静态block吗?如果不是,如何优雅地模拟?我想替换像这样的东西:-classC{public:voidini(){/*somecode*/}};classD{std::vectorregis;//willini();laterpublic:Cfield1;public:Cfield2;public:Cfield3;//wheneverIaddanewfield,Ihaveto...#1public:D(){regis.push_back(&field1);regis.push_back(&field2);regis.push_back(&field3);//#1...al

c++ - constexpr 类的设计 : merging constexpr and non-constexpr versions?

考虑一个在运行时只包装一个值的类:templateclassNonConstValue{public:NonConstValue(constType&val):_value(val){;}Typeget()const{return_value;}voidset(constType&val)const{_value=val;}protected:Type_value;};以及它的constexpr版本:templateclassConstValue{public:constexprConstValue(constType&val):_value(val){;}constexprTypeg

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

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

c++ - xvalues : differences between non class types and class types

考虑下面的最小示例:#includestructS{};intmain(){Ss;std::move(s)=S{};}它编译没有错误。如果我改为使用非类类型,则会收到错误。例如,以下代码无法编译:#includeintmain(){inti;std::move(i)=42;}枚举、作用域枚举等也是如此。错误(来自GCC)是:usingxvalue(rvaluereference)aslvalue这背后的原理是什么?我想这是对的,但我想了解我可以对除非类之外的所有类型执行此操作的原因是什么。 最佳答案 C++允许对类对象右值进行赋值,

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

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

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++ 映射初始化错误 C2552 : non-aggregates cannot be initialized with initializer list

我正在尝试使用以下代码在header中初始化map,但它一直在标题中显示错误。我正在使用C++11,所以这应该是可能的,对吧?typedefstd::map>AnimationSpeedMap;AnimationSpeedMapAnimationSpeeds={{NPCAnimation::WALK,{{Direction::LEFT,sf::milliseconds(100)},{Direction::RIGHT,sf::milliseconds(100)},{Direction::UP,sf::milliseconds(200)},{Direction::DOWN,sf::mill

c++ - `int main(int argc, char* argv<::>)` 如何成为 main 的有效签名?

这个问题在这里已经有了答案:Howisthisbracketless/bracelesscodevalid?[duplicate](4个答案)关闭7年前。我在网站上看到intmain(intargc,char*argv)也可以用作main的签名.令人惊讶的是,以下程序:intmain(intargc,char*argv){return0;}编译时会发出GCC中的任何警告以及clang。它还在C++中编译。那么,intmain(intargc,char*argv)是怎么回事?是main的有效签名?

新创建多模块工程执行maven编译打包出现non-resolvable parent pom异常

新创建多模块工程在执行mvncleaninstall时抛出non-resolvableparentpom找不到父pom异常:[FATAL]Non-resolvableparentPOMforcom.alibaba:*****:[unknown-version]:Couldnotfindartifactcom.-parent:pom:-SNAPSHOTand‘parent.relativePath’pointsatnolocalPOM@line12,column10解决办法在子模块标签内添加:../pom.xml原因pomparent标签寻找路径:relativePath本地仓库远程仓库因为是新