草庐IT

expection

全部标签

c++ - 错误 : expected a declaration

到目前为止,我的DecisionTree.h文件中只有namespaceDecisionTree{publicstaticdoubleEntropy(intpos,intneg);}并且VisualStudio已经突出显示了public并说Error:expectedadeclaration.我错过了什么? 最佳答案 public是一个访问说明符。访问说明符仅适用于class/struct主体,不适用于namespace。在C++中(与Java不同)它必须在class主体内跟一个冒号:。例如,classDecisionTree{//

c++ - 使用模板方法时出现 "expected primary expression"错误

我有一些实现Pareto规则的通用代码。它看起来像是格式正确的代码。关于newResult.set(criterion());错误的GCC4.4编译器消息表达。但我找不到问题。完整错误日志:trunk$g++-std=c++0x-otesttest.cppt6.cpp:Inmemberfunction‘boolPareto,Types...>::operator()(Map&,Map&)’:t6.cpp:24:error:expectedprimary-expressionbefore‘>’tokent6.cpp:26:error:expectedprimary-expressionb

c++ - 将 googlemock EXPECT_CALL 与 shared_ptr 一起使用?

我有一个测试可以很好地使用原始指针,但我无法让它与std::shared_ptr一起工作。类是这样的:classMyClass{MyClass(SomeService*service);voidDoIt();}我的测试代码是这样的:classMyClassTests:public::testing::Test{public:MyClassTests():myClass_(newMyClass(&service_)){}protected:SomeServiceFakeservice_;MyClassSharedPointermyClass_;};TEST_F(MyClassTests,

C++ 错误 : Expected a type specifier

当我尝试像这样使用LoggerStream时,我得到“需要一个类型说明符”:constLoggerStreamlogger(L"测试组件");这是我尝试使用LoggerStream的地方:#include"Logger.h"#include"TestComponent.h"namespaceophRuntime{structTestComponent::TestComponentImpl{private:LoggerStreamlogger(L"TestComponent");NO_COPY_OR_ASSIGN(TestComponentImpl);};TestComponent::T

c++ - g++ 使用 "expected a type, got ' xyz' 拒绝我的简单仿函数”

我一直在研究C++中的仿函数。特别是,我有一个vector对,我想按对的第一个元素排序。我开始编写一个完全专门化的仿函数(即类似“boolMyLessThan(MyPair&lhs,MyPair&rhs)”的东西)。然后,仅仅因为这类东西很有趣,我想尝试编写一个通用的“将F应用于这对的第一个元素”仿函数。我写了下面的内容,但g++不喜欢它。我得到:错误:“templatestructPair1stFunc2”的模板参数列表中参数2的类型/值不匹配错误:需要一个类型,得到的是“less”#include#include#include#includetemplatestructPair1

c++ - 构造函数中的奇怪 "candidate expects 1 argument, 0 provided"

我正在用C++制作一个简单的线程服务器应用程序,事实上,我使用libconfig++来解析我的配置文件。好吧,libconfig不支持多线程,因此我使用两个包装类来完成“支持”。重点是,其中一个失败了:classapp_config{friendclassapp_config_lock;public:app_config(char*file):cfg(newlibconfig::Config()),mutex(newboost::mutex()){cfg->readFile(file);}private:boost::shared_ptrcfg;boost::shared_ptrmut

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++ - 错误 : expected unqualified-id before '<' token|

我收到以下错误:preprocessor_directives.cpp|15|error:expectedunqualified-idbefore'#includeusingnamespacestd;//Avoid.Using#defineforconstants#defineMY_CONST11000//Use.EquivalentconstantdefinitionconstintMY_CONST2=2000;//Avoid.Using#defineforfunctionlikemacros#defineSQR1(x)(x*x)//Use.Equivalentfunctiondef

c++ - 奇怪的 GCC 'expected primary expression...' 错误

这个问题在这里已经有了答案:关闭12年前。PossibleDuplicate:Templates:templatefunctionnotplayingwellwithclass’stemplatememberfunctiontemplatestructA{templatevoidf();};templatevoidF(A&a){a.f();//expectedprimary-expressionbefore‘)’token}intmain(){Aa;a.f();//Thisoneisok.}这是怎么回事?

c++ - #define 导致 "expected primary-expression"错误

#defineN10;intmain(){intx;for(inti=0;i用g++编译的结果:test-define.cpp:Infunction‘intmain()’:test-define.cpp:7:22:error:expectedprimary-expressionbefore‘;’tokentest-define.cpp:7:22:error:expected‘)’before‘;’tokentest-define.cpp:7:24:error:namelookupof‘i’changedforISO‘for’scoping[-fpermissive]test-defin