草庐IT

has-scope

全部标签

c++ - "gets() was not declared in this scope"错误

这个问题在这里已经有了答案:whyg++shows"gets()"notdeclared,evenafterincluding(3个答案)关闭2年前。使用以下代码,我得到“gets()未在此范围内声明”错误:#include#includeusingnamespacestd;intmain(){//stringstr[]={"Iamaboy"};stringstr[20];`gets(str);cout

c++ - 警告 C4180 : qualifier applied to function type has no meaning; ignored

我已经设置了编译器/Za选项来禁用语言扩展,以便编译器严格使用标准ISOC++。这是我收到以下警告的示例接口(interface)类warningC4180:qualifierappliedtofunctiontypehasnomeaning;ignored这是关于函数返回类型中的const限定符,如果我删除const,警告就会消失,但我不想这样做,我想重新启用lanqage扩展。我的问题是:这个警告合理吗?如果不是,那么我将使用pragma禁用警告,但在此之前我想确保此警告是“误报”因为下面的类是正确的ANSIISOC++不是吗?所以警告应该被禁用?classIBet{public:

c++ - 错误 C2995 : function template has already been defined

此代码产生17错误C2995:函数模板已被定义;在添加#include"set.h"header之前存在一组单独的错误。有一个与此关联的私有(private).cpp和.h文件。/**File:private/set.cpp*LastmodifiedonThuJun1109:34:082009byeroberts*-----------------------------------------------------*Thisfilecontainstheimplementationoftheset.hinterface.*BecauseofthewayC++compilestemp

c++ - 在顶层使用 shared_ptr 而不是 scoped_ptr 有什么优势吗?

我的团队对于指针容器在特定上下文中的使用存在一些分歧。请考虑:intmain(){//Toplevel.Thisisanimportantfacttothecontext//i.e.thatthefollowinginstanceisatthislevel//sothatitsmembersareessentiallyatprogramscope.MainClassmainClass;mainClass.run();}//AinstanceofaclassderivedfromBufferdoessomethingverycomplex//(ithasvarioushandlestor

c++ - 错误 : 'ios_base' has not been declared

我正在使用libcurl下载序列化代码并将其打开,但是,我收到一个错误,看起来fstream丢失了,但它包含在内。我环顾四周,但很少发现错误。下面是错误和代码。错过了什么?编译错误输出g++-gtestGetprice2.cpp-otestGetprice2.o-std=gnu++11-lcurltestGetprice2.cpp:Infunction'intgetData()':testGetprice2.cpp:45:56:error:'ios_base'hasnotbeendeclaredtestGetprice2.cpp:45:72:error:'ios_base'hasnot

c++ - GNU 编译器 vs. Visual Studio 在数组上分配 w/Length Constant w/in a Scope

我知道如果你在c/c++中设置一个动态值,你不能在括号内使用该值来分配一个数组(这会使它成为所谓的可变长度数组(VLA),其中currentC++standard不支持)...即见:C++:VariableLengthArrayhttp://en.wikipedia.org/wiki/Variable-length_array我不太明白(而且我在这里没有看到确切地问到的)是为什么GNUc/c++编译器(gcc、g++)没问题使用基于整数值的动态分配(据我所知),只要该值是数组分配范围内的常量,但VisualStudio不支持这一点并且将拒绝编译代码,吐出错误。例如在g++中voidFo

c++ - boost::scoped_lock 不适用于局部静态变量?

我制作了以下示例程序来使用boost线程:#pragmaonce#include"boost\thread\mutex.hpp"#includeclassThreadWorker{public:ThreadWorker(){}virtual~ThreadWorker(){}staticvoidFirstCount(intthreadId){boost::mutex::scoped_lock(mutex_);staticinti=0;for(i=1;i主类://ThreadTest.cpp#include"stdafx.h"#include"boost\thread\thread.hpp

c++ - "member of type foo has private copy constructor"错误 : why's it an error?

我试图定义这样一个类:#includeclassmy_class{private:someone_elsesfoo;public:myclass();~myclass();//...};但是编译器失败了:“someone_elses类型的字段foo有一个私有(private)的复制构造函数”。现在我知道我可以通过以下方式解决这个问题:classmy_class{private:someone_elses*foo;//...};my_class::my_class(){foo=newsomeone_elses();}my_class::~my_class(){deletefoo;}我的问

c++ -/boost/lockfree/queue.hpp: 错误: 静态断言失败: (boost::has_trivial_destructor<T>::value)

我正在尝试替换boost::lockfree::queue对于std::queue在这个文件中https://github.com/zaphoyd/websocketpp/blob/experimental/examples/broadcast_server/broadcast_server.cpp我添加了#include;改线130,std::queuem_actions;,至boost::lockfree::queuem_actions;;删除所有与锁定有关的行;并更改了行103,m_actions.pop();,至m_actions.pop(a);.我在sconsbroadcas

c++ - 错误 : aggregate 'first one' has incomplete type and cannot be defined

我写了这个头文件(header1.h):#ifndefHEADER1_H#defineHEADER1_Hclassfirst;//intsumm(inta,intb);#endif和这个源文件(header1.cpp和main.cpp):#include#include"header1.h"usingnamespacestd;classfirst{public:inta,b,c;intsum(inta,intb);};intfirst::sum(inta,intb){returna+b;}#include#include"header1.h"usingnamespacestd;firs