繁体   English   中英

使用“具有”关系或构图将向量从一个类转移到另一个类

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM