簡體   English   中英

錯誤:“數字”之前的預期類型說明符

[英]error: expected type-specifier before ‘Number’

我試圖找出以上錯誤,但無濟於事。 每次編譯時,我都會收到錯誤消息:

/home/duncan/Desktop/OOPS/dac80/json/parser.cpp: In function 'Value* parseString(std::stringstream&)': /home/duncan/Desktop/OOPS/dac80/json/parser.cpp:149:19: error: expected type-specifier before 'String' Value* val = new String(name);

我已經驗證我在源文件中包括了正確的頭文件,以便編譯器可以識別該文件。 以下是有關錯誤的代碼

Parser.cpp:

 #include "object_model.h" Value* parseString(std::stringstream& in) { std::string name("123"); Value* val = new String(name); return val; } 

object_model.hpp:

 #ifndef OBJECTMODEL_H #define OBJECTMODEL_H #include <string> #include <sstream> #include <map> #include <vector> enum ValueType { Object = 0, Array = 1, String = 2, Number = 3, True = 4, False = 5, Null = 6}; class Value { public: Value() {} virtual ValueType getType() = 0; }; class String : public Value { public: String(std::string content); ~String(); std::string content; virtual ValueType getType(); }; #endif 

object_model.cpp:

 #include "object_model.h" String::String(std::string content) { this->content = content; } String::~String() { } ValueType String::getType() { return (ValueType)2; } 

我注意到的另一件事是,如果我將String更改為Text,則代碼將完全編譯。 不知道為什么,但是名稱String是否會與std :: string類沖突?

克里斯說“不,它與您的其他字符串標識符沖突”的意思是,您的“類字符串”與“枚舉ValueType {對象= 0,數組= 1,字符串= 2,數字= 3,True = 4,False = 5,Null = 6};“,因此編譯器會看到

Value* val = new String(name);

Value* val = new 2(name);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM