草庐IT

useful_line

全部标签

c++ - 错误 C2899 : typename cannot be used outside a template declaration

我正在MSV2010中尝试以下内容namespacestatismo{templatestructRepresenterTraits,3u>>{typedefitk::Image,3u>VectorImageType;typedefVectorImageType::PointerDatasetPointerType;typedefVectorImageType::PointerDatasetConstPointerType;typedeftypenameVectorImageType::PointTypePointType;typedeftypenameVectorImageType:

c++ - 警告 C4114 : same type qualifier used more than once

在将VC++6.0开发的代码迁移到VisualStudio2008时,我在代码的下面一行中收到此警告。constintconstCImportContext::PACKETSIZE=4096;我知道如何修复指针staticconstintconst*PACKETSIZE;//C4114staticconstint*constPACKETSIZE;//Correct但我的问题是如何解决这个警告,如果它像下面的警告(没有指针),staticconstintconstPACKETSIZE; 最佳答案 指针有两种不同的const限定符是有意

c++ - boost shared_ptr use_count 函数

我的申请问题如下-我有一个大结构foo。因为它们很大并且出于内存管理的原因,我们不希望在数据处理完成后删除它们。我们将它们存储在std::vector>.中我的问题与了解所有处理何时完成有关。第一个决定是我们不希望任何其他应用程序代码在结构中标记一个完整的标志,因为程序中有多个执行路径,我们无法预测哪一个是最后一个。因此在我们的实现中,一旦处理完成,我们将删除boost::shared_ptr>的所有拷贝除了vector中的那个。这会将shared_ptr中的引用计数器降为1。使用shared_ptr.use_count()查看它是否等于1以了解我的应用程序的所有其他部分何时处理完数据

c++ - C++ 中没有 `while (!my_ifstream.eof()) { getline(my_ifstream, line) }`?

关于thiswebsite,有人写道:while(!myfile.eof()){getline(myfile,line);cout这是错误的,请仔细阅读eof()的文档成员函数。正确的代码是这样的:while(getline(myfile,line))cout这是为什么? 最佳答案 有两个主要原因。@Etienne指出了一个:除了到达文件末尾之外的其他原因,读取可能会失败,在这种情况下,您的第一个版本将进入无限循环。然而,即使没有其他故障,第一个也无法正常工作。eof()不会被设置,直到after由于到达文件末尾而导致读取失败。这意

c++ - (SWIG C++ 到 Python)警告 301 : class keyword used, 但不是在 C++ 模式下

我正在尝试为python编译C++扩展。我创建了一个接口(interface)文件foo.i,如下所示:%modulefoo%include"typemaps.i"//Forpointerstoprimitivetypes%include"std_string.i"//std::stringmapping%applyconststd::string&{std::string*foo};//datatypescontainingstd::stringmembers%{#defineSWIG_FILE_WITH_INIT#include"../path/to/c++/header/file

c++ - 函数指针 : is the simple canonical use bad from a performance point of view? 如果是的话,c++11-ish 的替代方案是什么?

我在我的c++代码中经常使用函数指针,总是以符合这个简单规范示例的方式使用(例如,函数具有相同的I/O,但所需的操作只是在运行时已知):#includeusingnamespacestd;intadd(intfirst,intsecond){returnfirst+second;}intsubtract(intfirst,intsecond){returnfirst-second;}intoperation(intfirst,intsecond,int(*functocall)(int,int)){return(*functocall)(first,second);}intmain()

c++ - 共享指针不增加 use_count

我正在尝试了解如何在C++中使用std::shared_ptr。但这很令人困惑,我不明白如何创建指向同一对象的多个共享指针。甚至文档和在线资料也不是很清楚。以下是我编写的一小段代码,用于尝试理解std::shared_ptr的行为:#include#includeusingnamespacestd;classNode{public:intkey;Node(){key=0;}Node(intk){key=k;}};intmain(){Nodenode=Node(10);shared_ptrptr1((shared_ptr)&node);coutptr2=make_shared(node)

c++ - 错误记录 C++ 预处理器宏 __LINE__、__FUNCTION__

我试图将一个简单的错误记录合并到我现有的应用程序中,目前它仅使用cout报告错误所以我希望使用保持类似的界面运算符(operator)。但是我希望它记录该行并运行发生的错误,但我不想输入__LINE__,__FUNCTION__每次我需要登录。有谁知道我可以用来允许__LINE__的技巧吗?要在另一个函数中使用的宏,而不是报告调用行?希望这是有道理的。classmyLogClass{uint8_tlevel;public:booloperator而不是每次都这样myLogClass我只想能够做到:myLogClass 最佳答案 my

c++ - 错误 : Label "foo" used but not defined

所以我在使用一些C++代码时遇到了前面提到的错误,代码看起来有点像这样:#includeusingnamespacestd;charfoodstuffs;voidfruit(){cin>>foodstuffs;switch(foodstuffs){case'a':gotofoo;break;case'b':gotofooo;break;}}intmain(){cout确切的代码要复杂得多,但这只是为了向您展示我遇到的错误。现在我意识到每个人都出于某种原因鄙视“goto”语句,但我的实际代码中充满了太多的goto,以至于我真的没有时间/耐心回去更改它们。此外,我是一名新手程序员,我发现g

c++ - 错误 : expected primary-expression before ‘>’ : templated function that try to uses a template method of the class for which is templated

这个问题在这里已经有了答案:WhereandwhydoIhavetoputthe"template"and"typename"keywords?(8个答案)关闭8年前。在使用模板和仿函数(未出现在这个问题中)时,我最终遇到了以下简化的问题。以下代码(也可用here)classA{public:templateboolisGood(intin)const{constTf;returninbooltryEvaluator(T&evaluator,intvalue){returnevaluator.isGood(value);}intmain(intargc,constchar*argv[]