Placing a class object inside a vector?

前端 未结 4 1826
情歌与酒
情歌与酒 2021-01-28 23:43

I noticed that I can place a Class inside a vector; here is my program, where I am receiving the following error:

/out:blackjack.exe
blackjack.obj
blackjack.obj         


        
相关标签:
4条回答
  • 2021-01-29 00:14

    You'll have to instantiate the vector somewhere as it's a static. Basically, you want something like:

    std::vector<Card> Card::Cards;
    

    somewhere in your code.

    0 讨论(0)
  • 2021-01-29 00:17

    Your cards vector is defined as static. That means it is effectively a global variable that you must define. This can be done by putting the following after the class definition of Card:

    std::vector<Card> Card::Cards();
    
    0 讨论(0)
  • 2021-01-29 00:18

    You are declaring the static member Cards inside the class definition, but you aren't defining it anywhere. Add a definition after the class definition:

    vector<Card> Card::Cards;
    
    0 讨论(0)
  • 2021-01-29 00:20

    You have to actually declare your vector.

    0 讨论(0)
提交回复
热议问题