草庐IT

name_list

全部标签

c++ - 错误 : ‘i’ does not name a type with auto

这个问题在这里已经有了答案:HowdoIenableC++11ingcc?(4个答案)关闭7年前。我是C++新手,这是我的程序#include#include#include#include#includeintmain(){staticconstdoublearr[]={16.0,2.2,77.5,29.0,24.0};std::vectorvec(arr,arr+sizeof(arr)/sizeof(arr[0]));std::transform(vec.begin(),vec.end(),vec.begin(),bind2nd(std::minus(),3.0));for(aut

c++ - 错误 : '...' does not name a type

我有一个工作项目。重新安排一些代码后,我尝试重新编译我的项目,然后奇怪的事情开始发生。查看编译器输出的这段摘录。我正在使用MinGWG++从Windows上的Eclipse进行编译。****BuildofconfigurationDebugforprojectPract2********InternalBuilderisusedforbuild****g++-O0-g3-Wall-c-fmessage-length=0-omove.o..\move.cppInfileincludedfrom..\/game.h:11:0,from..\/piece.h:10,from..\/move.

c++ - 继承 : expected class-name before ‘{’ token

我试图在C++中创建一个异常类,但它不起作用。我已将代码减少到最少,但仍然找不到错误。这是我的头文件:#ifndefLISTEXCEPTION_H#defineLISTEXCEPTION_H//C++standardlibraries#include/*CLASSDEFINITION*/classListException:publicexception{};#endif//LISTEXCEPTION_H这是我得到的错误:error:expectedclass-namebefore‘{’token这是出乎意料的。我该如何解决这个问题? 最佳答案

c++ - 为什么我不能将 boost::function 存储在 std::list 中?

我得到以下编译错误:error:expected`;'before'it'"这是我的代码:#include#includetemplatevoidexample(){std::list>::iteratorit;}为什么会这样?我该如何解决? 最佳答案 您需要将typename放在该行的前面,因为您执行::iterator的类型取决于模板参数T。像这样:templatevoidexample(){typenamestd::list>::iteratorit;}考虑这条线std::list>::iterator*it;这可能意味着乘法

c++ - 指向 typeinfo::name() 的内存的生命周期是多少?

在C++中,我可以使用typeid运算符来检索任何多态类的名称:constchar*name=typeid(CMyClass).name();返回的constchar*指针指向的字符串对我的程序可用多长时间? 最佳答案 只要带有rtti的类存在。因此,如果您处理单个可执行文件-永远。但是对于动态链接库中的类,它会发生一点变化。可能你可以卸载它。 关于c++-指向typeinfo::name()的内存的生命周期是多少?,我们在StackOverflow上找到一个类似的问题:

c++ - 指向成员函数的指针 - C++ std::list 排序

如何将指向成员函数的指针传递给std::list.sort()?这可能吗?谢谢structNode{uint32_tID;char*Value;};classmyClass{private:uint32_tmyValueLength;public:listMyQueue;boolcompare(Node*first,Node*second);booldoStuff();}boolmyClass::compare(Node*first,Node*second){unsignedintii=0;while(iiValue[ii]Value[ii]){returntrue;}elseif(f

c++ - 删除 std::list::iterator 不会使迭代器无效并销毁对象吗?

为什么下面打印2?listl;l.push_back(1);l.push_back(2);l.push_back(3);list::iteratori=l.begin();i++;l.erase(i);cout我知道erase返回什么,但我想知道为什么这样可以?或者它是未定义的,还是取决于编译器? 最佳答案 是的,这是未定义的行为。您正在取消引用一种野指针。在erase之后,您不应该使用i的值。是的,erasedestructs指向的对象。但是,对于POD类型,销毁不会执行任何操作。erase不会为被删除的迭代器分配任何特殊的“空”

c++ - std::shuffle 不能用 std::list 编译

我正在尝试打乱一些生成元素的列表。这是代码:std::default_random_enginegenerator(10);std::listlist(10);intn=0;std::generate(list.begin(),list.end(),[&]{returnn++;});std::shuffle(list.begin(),list.end(),generator);它不编译。以下是错误:/include/c++/v1/algorithm:3059:34:Invalidoperandstobinaryexpression('std::__1::__list_iterator'

C++ list<T>::iterator 不能在派生类模板中使用

g++编译器给出了这个错误:expected`;'在“它”之前templateclassmyList:publicstd::list{public:voidfoo(){std::list::iteratorit;//compilererrorasabovementioned,why???}};谢谢。 最佳答案 在g++中。每当在模板中看到错误时:error:expected';'before'it'怀疑你需要一个类型名:typenamestd::list::iteratorit;当您在模板中声明了一个依赖于一个或多个模板参数的新类型

c++ - 从 std::list 中移除具有特定值的元素

我需要从std::list中删除具有特定值的元素。随着list我使用了remove()方法。现在我有list所以我想我应该使用remove_if()但它的谓词只需要一个参数-要测试的元素。如何编写函数foo(constCMyClass&Bad)从列表中删除所有等于Bad的元素?谢谢附言structCMyClass{void*Ptr;intVar;}boolis_equal(constCMyClass&A,constCMyClass&B){if(A.Ptr==B.PrtandA.Var==B.Var)returntrue;elsereturnfalse;} 最