English 中文(简体)
g++ 中的无益错误消息
原标题:Unhelpful error message in g++
  • 时间:2012-05-22 14:25:31
  •  标签:
  • g++

g++ 4.1.2 的错误信息遍布各地,

<file>:<line>: error: expected primary-expression before  int 
<file>:<line>: error: expected  ;  before  int 
<file>:<line>: error: invalid use of qualified-name  ::SuccessCode 

当它发生时的代码 就这么简单:

class Test
{
  static Status debug_function(void)
  {
    return Status::SuccessCode();   // this would be <file>:<line> mentioned above
    // and this one too:
    // return Status::FailureCode("test");
  }
};

这里为状态代码( and yes it squote including, 因为如果包含的文件无效, 我就会有错误 ):

namespace CODES
{
  enum Values { Success = 0, Failed = 1 };
}

class Status
{
private:
  CODES::Values code;
  string msg;
public:
  Status(CODES::Values val, const string &i_msg ): code(val), msg(i_msg) {}

  static Status SuccessCode(void)
  {
    return Status(CODES::Success, "");
  }

  static Status FailureCode(const string &fail_msg)
  {
    return Status(CODES::Failed, fail_msg);
  }
};

那么,这个代码有什么问题?它按照VC++进行正确编译!

事实上,成功代码和失败代码的代码在 *.cpp 文件中。 我把它们放入课堂声明, 因为错误信息仍然相同!

最佳回答

如果没有完整的程序,我不得不猜测。我的猜测是:在您的程序中某处有

问题回答

暂无回答




相关问题
C++ GNU linker errors

I m trying to compile my program on Windows via Cygwin with the compilation command: g++ ping.cpp -I./include -L./lib -lchartdir50 I m using an API called ChartDirector which draws charts for me. I ...

处理多重定义错误[封闭]

I m试图汇编一些C++文档。 • 在连接阶段(汇编工作)发现以下几类错误:

G++ Compilers for MonoDevelop

How do you setup a G++ compiler for MonoDevelop? On both OS X and Windows Vista the default install complains about "Compiler Not Found: g++". Is MonoDevelop not a good cross platform IDE for C++ ...

<list> retreving items problem with iterator

I have a list of type Instruction*. Instruction is a class that I made. This class has a function called execute(). I create a list of Instruction* list<Instruction*> instList; I create an ...

problem w/ linking static function g++

I am trying to build a small program and I have my own library libfoo. I have a camera class that is calling a static function from my Vector3 class (i.e. crossProduct). My camera class and Vector3 ...

"g++" and "c++" compiler

I just found on my Ubuntu, there are two different C++ compilers: /usr/bin/g++ and /usr/bin/c++. I am not familiar with the latter, but man c++ just jumps to the manpage of gcc. I wonder what is their ...