草庐IT

filter_has_var

全部标签

c++ - 转发声明结构时出错 : "has a previous declaration here"

在构建我的小型C++项目时,出现以下2个错误,无法找出原因:错误:在“结构”之后使用类型定义名称“TTF_Font”。指向Foo.h中的以下代码行:structTTF_Font;。错误:“TTF_Font”在此之前有一个声明。指向以下代码行:typedefstruct_TTF_FontTTF_Font;inSDL_ttf.h。我已将其缩小到新测试项目中的以下文件:Foo.h:#ifndefFOO_H#defineFOO_HstructTTF_Font;classFoo{TTF_Font*font;};#endif//FOO_HFoo.cpp:#include"Foo.h"#includ

c++ - std::reverse_copy "error: function call has aggregate value"

#include#include#include#includeusingnamespacestd;intmain(){intarrA[]={1,2,3,4,5,6,7,8,9};vectorvecIntA(arrA,arrA+sizeof(arrA)/sizeof(arrA[0]));vectorvecIntB(vecIntA.size());//copy((vecIntA.rbegin()+3).base(),(vecIntA.rbegin()+1).base(),vecIntB.begin());//OKvector::iterators=(vecIntA.rbegin()+3)

c++ - 继承与聚合以及 "has-a"与 "is-a"。

在我的代码中,我发现使用类似混合的继承来组合具有不同block的对象很有用。我有:className{public:typedefint32_tvalue_type;public://ctorsanddtorsvoidset_value(value_typevalue){value_=value;}constvalue_type&value()const{returnvalue_;}private:value_typevalue_;};classNamedObject{public:voidset_name(constName&name){name_=name;}constName&n

c++ - 为什么我们在定义指针时使用 "type * var"而不是 "type & var"?

我是C++的新手(断断续续有大约一年的经验)。我很好奇是什么导致决定将type*name作为定义指针的语法。在我看来,语法应该是type&name因为&符号在代码中的其他任何地方都使用来引用变量的内存地址。因此,使用int指针的传统示例:inta=1;int*b=&a;会变成inta=1;int&b=&a我确信这其中有一些我没有看到的原因,我很想听听C++老手的一些意见。谢谢,-S 最佳答案 C++采用了C语法。正如“TheDevelopmentoftheCLanguage”(DennisRitchie着)中所揭示的那样,C在类型声

c++ - g++ 表示 : warning: statement has no effect for shift bits operators

我正在实现alkhwarizmi算法。没错,但我的g++编译器不喜欢移位运算符:>>和当我编译它时,我得到这个输出:>g++-Wall-std=c++0x-o"Al-khwarizmialgorithm.o""Al-khwarizmialgorithm.cpp"(indirectory:/home/akronix/workspace/Algorithms)>Al-khwarizmialgorithm.cpp:Infunction‘intalkhwarizmi(int,int)’:Al-khwarizmialgorithm.cpp:31:9:warning:statementhasnoe

c++ - g++ 不喜欢模板 var 上的模板方法链接?

我正在尝试使用g++编译一些以前在VisualC++2008ExpressEdition下开发的代码,看起来g++不允许我调用模板方法在模板变量的方法返回的引用上。我能够将问题缩小到以下代码:classInner{public:templateTget()const{returnstatic_cast(value_);};private:intvalue_;};classOuter{public:Innerconst&get_inner(){returninner_;};private:Innerinner_;};templateintdo_outer(T&val){returnval

Qt : has initializer but incomplete type 中的 C++ 错误

voidFindWords::getTextFile(){QFilemyFile(":/FindingWords2.txt");myFile.open(QIODevice::ReadOnly);QTextStreamtextStream(&myFile);QStringline=textStream.readAll();myFile.close();ui->textEdit->setPlainText(line);QTextCursortextCursor=ui->textEdit->textCursor();textCursor.movePosition(QTextCursor::S

c++ - 为什么即使在非常简单的情况下,volatile vars 也没有得到优化?

如果我编译代码intmain(){inti;i=1;i=2;}在带有发布和优化的VS中,反汇编看起来像:intmain(){inti;i=1;i=2;}010D1000xoreax,eax010D1002ret但是如果我写“volatile”这个词:intmain(){01261000pushecxvolatileinti;i=1;01261001movdwordptr[esp],1i=2;01261008movdwordptr[esp],2}0126100Fxoreax,eax01261011popecx01261012ret有谁知道为什么VS留下这段代码?它有任何副作用吗?它是程序

c++ - if( var == 'x' ) 这样的语句中的文字存储在哪里?

像这样说charvar;if(var=='x');我们是否首先为“x”分配任何内存?如果是,它是哪个(堆栈/数据)?谢谢! 最佳答案 值“x”可以作为比较指令的一部分直接存储在代码段中,也可以存储在代码段中以立即加载到寄存器中,或存储在数据段中以间接加载或比较。这取决于编译器。 关于c++-if(var=='x')这样的语句中的文字存储在哪里?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/ques

C++ fatal error C1001 : An internal error has occurred in the compiler

在Release模式下编译时出现以下错误。1>d:\users\eyal\projects\code\yalla\core\src\runbox\win32\window.cpp:fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'f:\dd\vctools\compiler\utc\src\p2\main.c',line249)1>Toworkaroundthisproblem,trysimplifyingorchangingtheprogramnearthelocationslistedab