草庐IT

more_set_headers

全部标签

c++ - header guard 难题 - 已经在 .obj 问题中定义

我有一个类(A),它必须包含两个文件,X类和Y类。不幸的是,Y类还需要在其头文件中包含X类,因为构造函数将指向X类类型的指针作为参数.潜在的问题是会出现链接器错误?因为A类现在有两个X类的拷贝,一个它需要使用,一个来自Y类。在这种情况下,headerguards是没有用的。我的问题是-这纯粹是结构性问题还是有解决办法?我真的宁愿不在类Y的头文件中包含任何内容,以防我想在其他任何内容中包含它,但由于函数原型(prototype),是否有必要这样做? 最佳答案 如果您有以下情况:X.h#ifndefX_H__#defineX_H__cl

c++ - 无效的模板相关成员函数模板推导 - 认为我正在尝试使用 std::set

我有一个继承自基类模板的类模板。基类模板有一个数据成员和一个我想从父类(superclass)中调用的成员函数模板。我知道为了消除对成员函数模板的调用的歧义,我必须使用template关键字,我必须明确提及this在父类(superclass)中。this->base_member_obj.templatemember_function();这一切都很好,只是我使用的代码库犯了一个相当不幸的错误,即导入了整个namespacestd。,我试图调用的模板成员函数称为set.框架中的某处std::set包含在内,这导致GCC认为我正在尝试声明std::set而不是调用成员函数set.GCC

c++ - 我们什么时候应该为 `std::unordered_set` 提供我们自己的哈希函数

当我编译下面的代码时,我看到了与Hash相关的错误。intF_no_meaningA(unordered_set>&setVec,vector&vec){setVec.insert(vec);return1;}intmain(){vectorW{2,3,7};unordered_set>setVec;}$g++--versiong++(Ubuntu/Linaro4.6.3-1ubuntu5)4.6.3$g++$1.cpp-o$1-g-Wall-Weffc++-pedantic-std=c++0x/tmp/ccCQFQ4N.o:Infunction`std::__detail::_Has

c++ - 定义一个类的私有(private)整型常量 : in the header or in the cpp file?

主题主要在此处解决(Wheretodeclare/defineclassscopeconstantsinC++?)特别是here.我想完全理解的是,在积分常数的情况下,它们之间有什么区别://IntheheaderclassA{private:staticconstintmember=0;//Declarationanddefinition};和://IntheheaderclassA{private:staticconstintmember;//Onlydeclaration};//InthecppconstintA::member=0;//Definition(据我所知,第二种可能

c++ - gcc 预编译 header 的奇怪行为

我在让预编译的头文件工作时遇到了麻烦,所以我想到了以下最小工作示例。这是头文件foo.h#includeusingnamespacestd;voidhello(){cout我将它编译为g++-cfoo.h给我一个编译后的头文件foo.gch。我希望当我编译以下包含foo.h的源文件时,它应该选择headerfoo.h.gch并且我很好。//test.cpp#include//Swaporderinglater#include"foo.h"//------------------intmain(){hello();}但令人惊讶的是,这并没有使用foo.h.gch进行编译,而是使用了foo

c++ - 具有自定义结构的 <set> 包含重复项

我一直在学习C++。我被这个问题困住了。我有一个包含自定义结构的集合,该结构包含两个longint的a和b。我有一个自定义比较器结构,用于比较数字并在a或b不同时返回true。typedeflongintli;structnumber{number(lia1,lib1):a(a1),b(b1){}lia,b;};structcompare{booloperator()(constnumber&lhs,constnumber&rhs)const{returnlhs.a!=rhs.a||lhs.b!=rhs.b;}};intmain(){setnums;nums.insert(number

c++ - 我可以使用我的 header 的精简版包含在库中吗?

我的意思是我真正的头文件可以是这样的:#include"some_internal_class.h"classMyLibrary{Typeprivate_member;voidprivate_function();public:MyLibrary();voidfunction_to_be_called_by_library_users();};现在我想生成一个包含所有必要定义的动态库。我想随附一个header,而不是随附我库中的每个header。所以我想我可以像这样创建我的标题的精简版:classMyLibrary{public:MyLibrary();voidfunction_to_

c++ - 通过与不同类型的值进行自定义比较来查找 std::set 的元素

考虑以下带有自定义比较器的std::set玩具示例:#includestructA{A():a(cnt++){}constinta;staticintcnt;};intA::cnt=0;structcomp{booloperator()(constA&left,constA&right){returnleft.asa;for(inti=0;i请注意,A不能简单地从整数创建。我想在sa中寻找给定值为A::a的A,无需构造aA类型的临时对象,即我正在搜索类似的东西sa.find(4)带有自定义比较器,允许直接比较整数与A类型的对象。这可能吗? 最佳答案

c++ - boost spirit header 已弃用

我正在遵循boost::spirit的快速入门指南,当我包含时收到此编译器警告:“此header已弃用。请使用:boost/spirit/include/classic_core.hpp”我应该担心这个吗?(快速入门指南:http://spirit.sourceforge.net/distrib/spirit_1_8_5/libs/spirit/doc/quick_start.html,以及我要在这里编译的程序的完整源代码:http://spirit.sourceforge.net/distrib/spirit_1_8_5/libs/spirit/example/fundamental

c++ - 编译错误 - std::set with const 成员

我这辈子都弄不明白这段代码有什么问题:ClassA&doSomething(std::setconst>const&someSet){std::set>secondSet;for(std::setconst>::const_iteratorit=someSet.begin();it!=someSet.end();it++){if(checkSomething(*it))secondSet.insert(boost::const_pointer_cast(*it));}}当我尝试编译时,在g++的第4行(for循环的开始)出现以下错误:/usr/include/c++/4.4/ext/n