简体   繁体   中英

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. 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. I also made sure to include my Read.h in my 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.

What does mean <string> in this definition? 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. Maybe you meant simply

Read sentenceVector;

Also the parameter definition in the constructor

Sentence(const string&, const Read vector <string>&);

is invalid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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