[英]putting a vector from one class to another using the “has a” relationship or composition
I created a class called Read to store sentences into a vector. 我创建了一个名为Read的类,将句子存储到向量中。 This class works fine.
该课程效果很好。 However when I want to use this vector in my new Class called Sentence by using composition, I get an errors.
但是,当我想通过使用合成在新的名为Sentence的类中使用此向量时,出现错误。 I also made sure to include my Read.h in my Sentence.h
我还确保将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
};
These are the errors I get 这些是我得到的错误
./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 errors generated. 产生2个错误。
What does mean <string>
in this definition? 在此定义中
<string>
是什么意思? Is the class Read a template class? 该课程是读模板课程吗?
const Read <string> sentenceVector;
I think there should be 我认为应该有
const Read sentenceVector;
Also if this data member is const you may not change it. 同样,如果此数据成员是const,则不能更改它。 Maybe you meant simply
也许你的意思只是
Read sentenceVector;
Also the parameter definition in the constructor 也是构造函数中的参数定义
Sentence(const string&, const Read vector <string>&);
is invalid 是无效的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.