草庐IT

non-main

全部标签

c++ - 在通过在 main 中声明数组来解决之前,数组绑定(bind)不是整数常量

程序1#includestd::size_tthree(){return3;}inti[three()];intmain(){return0;}方案二std::size_tthree(){return3;}intmain(){inti[three()];return0;}这里的问题是程序1如预期的那样给出了编译错误"error:arrayboundisnotanintegerconstantbefore']'token"但是不知道为什么程序2编译成功了? 最佳答案 C99允许inti[three()];声明一个变长数组,但只允许if

c++ - "If you' 已经写了一个编译测试,你've written a call to main"

在程序中调用mainviolatesC++标准voidf(){main();//anendlessloopcallingmain?Nothat'snotallowed}intmain(){staticint=0;std::cout在lecture中ChandlerCarruth,大约在“22.40”说ifyou'vewrittenacompilertestyou'vewrittenacalltomain这有什么关系,或者如何克服标准不允许的事实? 最佳答案 这里的要点是,如果你编写编译器测试代码,你可能会想用一些不同的参数集测试调用

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

我有以下功能(简化示例):QByteArrayDecompressBytes(constQByteArray&content){/*functionbody(withotherreturnexpressions)*/do{returncontent;}while(content.size()!=0);}添加最后一行用于测试,替换使用的宏。VisualStudio没有发现此代码有问题,但g++生成了warning:controlreachesendofnon-voidfunction[-Wreturn-type]将最后一行更改为returncontent;删除警告。我的问题:为什么编译器

c++ - 使 main() "uncrashable"

我想编写一个守护进程管理器来确保所有守护进程都在运行,就像这样(简化的伪代码):voidwatchMe(filename){while(true){system(filename);//freezesaslongasfilenameruns//oh,filenamemustbecrashed.Nevermind,willberestarted}}intmain(){_beginThread(watchMe,"foo.exe");_beginThread(watchMe,"bar.exe");}这部分已经在工作了——但现在我面临的问题是,当观察到的应用程序——比如foo.exe——崩溃时

c++ - g++ 链接问题 : In function `_start' : (. text+0x20): undefined reference to `main'

我收到对主要错误的undefinedreference-即使我已经定义了主要,并且(AFAICT),我已经正确链接了它。这是我的代码和我使用的命令://################################################//proj1.h#ifndef__SCRATCH_PROJ1_H#define__SCRATCH_PROJ1_HintaddOne(inti);#endif/*__SCRATCH_PROJ1_H*///################################################//proj1.cpp#include"pr

c++ - 使用 -g 选项编译但 "Single stepping until exit from function main, which has no line number information"

我在使用gdb时遇到了一些问题。这是我在一个名为main.cpp的文件中的代码#includevoidmyfunc();intmain(){charmsg[]="HelloWorld!";myfunc();std::cout我使用这个命令来编译这段代码:g++-g-Wallmain.cpp-ofoo接下来,我使用了gdb:$gdbfoo(gdb)startTemporarybreakpoint1at0x80487c3Startingprogram:/home/laptop/workspace/fooTemporarybreakpoint1,0x080487c3inmain()(gdb)

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++ - 我如何声明一个放在 main 之后的类模板?

我正在尝试实现一个堆栈模板类。但是我想在main之前声明它。我可以这样做吗?我知道如果将main放在模板之后它会编译,但是是否可以先将main然后是模板?#include//startdeclarationoftemplatetemplateclassstack;//enddeclarationoftemplateintmain(){stacks(5);s.push('a');s.push('b');couts1(10);s1.push(3.2);s1.push(0.5);coutclassstack{T*s;intsize;//HowmanyelementsIcanstole.int

c++ - 处理 main 中的可选参数

假设我有一个main函数,它基本上只是调用另一个函数作为程序的入口点。该函数(以及整个程序)有一些强制参数和一些可选参数:#include#includevoidfunction_to_call(std::stringarg1,std::stringarg2,std::stringarg3,std::stringarg4,std::stringarg5="foo",std::stringarg6="bar",intnum1=1,intnum2=2){//dofancystuffhere}intmain(intargc,char**argv){intnum1,num2;std::stri

c++ - 当我们说操作系统的控制在程序执行时传递给 main() 函数时,我们是什么意思?

假设我们正在尝试运行任意程序-intmain(){statement1;statement2;statement3;}然后人们常说,在程序执行的过程中,操作系统的控制权被传递给了main()函数,在执行完main函数中的所有语句之后,控制权再次交还给操作系统。控制是什么意思?如果控制真的从操作系统传递给程序那么多个程序如何同时运行? 最佳答案 “控制”是“执行语句的能力”的简称。在你的程序运行之前,操作系统会执行语句将你的程序代码加载到内存中,而你的程序没有执行语句的能力(即没有控制权)。一旦您的程序加载并准备好运行,操作系统就会为