[英]putting a vector from one class to another using the “has a” relationship or composition
我創建了一個名為Read的類,將句子存儲到向量中。 該課程效果很好。 但是,當我想通過使用合成在新的名為Sentence的類中使用此向量時,出現錯誤。 我還確保將Read.h包含在Sentence.h中
class Sentence
{
public:
Sentence(const string&, const Read vector <string>&);
private:
string mString;
const Read <string> sentenceVector; //here I am trying to use the vector
//from the Read class
};
這些是我得到的錯誤
./sentence.h:10:37: error: cannot combine with previous 'type-name' declaration
specifier
Sentence(const string&, const Read vector <string>&);
^
./sentence.h:17:13: error: expected member name or ';' after declaration
specifiers
const Read <string> sentenceVector;
~~~~~~~~~~ ^
產生2個錯誤。
在此定義中<string>
是什么意思? 該課程是讀模板課程嗎?
const Read <string> sentenceVector;
我認為應該有
const Read sentenceVector;
同樣,如果此數據成員是const,則不能更改它。 也許你的意思只是
Read sentenceVector;
也是構造函數中的參數定義
Sentence(const string&, const Read vector <string>&);
是無效的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.