2016-01-07 145 views
0

有一個在我的代碼編譯錯誤 '*'(還沒有找到解決方案)之前:錯誤C2143:語法錯誤:缺少';'

#include <iostream> 
#include <vector> 
#include "command.h" 

extern std::istream *instream; 
extern std::vector<command> commands; 

這裏是command.h頭文件:

#define CMD_RETURN_TYPE_NONE 0 
#define CMD_RETURN_TYPE_STRING 1 
#define CMD_RETURN_TYPE_CHAR 2 
#define CMD_RETURN_TYPE_INT 3 
class command { 
    public: 
     virtual int getReturnType(void); 
     virtual char getOpName(void); 
     virtual void* call(void); 
} 

拋出下一個編譯錯誤

1>------ Build started: Project: MyFirstCPPApp, Configuration: Debug Win32 ------ 
1>Compiling... 
1>MyFirstCPPApp.cpp 
1>e:\anton\msvc++ projects\myfirstcppapp\myfirstcppapp\MyFirstCPPApp.h(5) : error C2143: syntax error : missing ';' before '*' 
1>e:\anton\msvc++ projects\myfirstcppapp\myfirstcppapp\MyFirstCPPApp.h(5) : error C2377: 'std::istream' : redefinition; typedef cannot be overloaded with any other symbol 
1>  E:\Anton\MSVS2008Express\VC\include\iosfwd(707) : see declaration of 'std::istream' 
1>e:\anton\msvc++ projects\myfirstcppapp\myfirstcppapp\MyFirstCPPApp.h(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 
1>.\MyFirstCPPApp.cpp(4) : error C2039: 'get' : is not a member of 'System::Int32' 
1>  c:\windows\microsoft.net\framework\v2.0.50727\mscorlib.dll : see declaration of 'System::Int32' 
1>.\MyFirstCPPApp.cpp(7) : error C3861: 'callCmd': identifier not found 
1>.\MyFirstCPPApp.cpp(11) : error C2440: '=' : cannot convert from 'std::istream *' to 'int *' 
1>  Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 
1>Build log was saved at "file://e:\Anton\MSVC++ Projects\MyFirstCPPApp\MyFirstCPPApp\Debug\BuildLog.htm" 
1>MyFirstCPPApp - 6 error(s), 0 warning(s) 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

我還沒有找到解決方案,該如何解決?

+0

什麼是'command'? 'command.h'分別。 –

+0

@πάνταῥεῖ是啊,command.h,這是抽象類 –

+0

請[edit](http://stackoverflow.com/posts/34653404/edit)你的問題添加這樣的信息。 –

回答

2

缺失; after:

class command { ... } ;

無論是在左括號還是分號(表示行的末尾)之間的任何內容都將被解析爲屬於此類的對象的可選列表。

因此,有必要在類定義之後添加分號,以便編譯器知道該類定義之後的任何內容都不是對象列表的一部分。

相關問題