How do I code and pass a (reference to a std::vector)?

前端 未结 2 1392
[愿得一人]
[愿得一人] 2021-01-23 19:22

I can\'t seem to get this right.

class Tree
{
    Node*   root;
    vector& dict;
} 

class Node
{
    vector& dict;
    char*   cargo;
    Node    left;         


        
2条回答
  •  半阙折子戏
    2021-01-23 19:53

    You can initialize a reference only in an initialization list of a constructor. For instance,

    Tree::Tree( vector& d ) : dict(d) 
    {
      ...
    }
    

提交回复
热议问题