简体   繁体   English

将Vector作为参数传递给另一个类构造函数C ++

[英]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) 我一直在尝试使用以下行将向量传递给另一个类的构造函数:(下面的代码行在Lexer.cpp类中)

 Parser p(toks);

where, toks is a vector of type Token ( vector<Token> toks; ) , with Token being a struct within the Lexer.h class. 其中,toks是Token类型的向量( vector<Token> toks; ),其中Token是Lexer.h类中的结构。

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); 但是,使用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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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