简体   繁体   中英

Passing a Vector as parameter to another class constructor C++

I have been trying to pass a vector to another class constructor by using the following line: (the following line of code is in the Lexer.cpp class)

 Parser p(toks);

where, toks is a vector of type Token ( vector<Token> toks; ) , with Token being a struct within the Lexer.h class.

The constructor to which I would like to pass this vector is the following:

Parser::Parser(vector<Lexer::Token> toks){
    //do something
}

However, using Parser p(toks); to pass the vector is giving me an 'Instantiating an unknown structure without a reference' error. In what way should I pass this vector to the other class?

add a & symbo

Parser::Parser(vector<Lexer::Token> &toks){
//do something
}

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