different types of objects in the same vector array?

后端 未结 4 1144
星月不相逢
星月不相逢 2020-12-19 19:46

I am using an array in a simple logic simulator program and I want to switch to using a vector to learn it but the reference I am using \"OOP in C++ by Lafore\" doesn\'t hav

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-19 20:30

    You are using

    vector(gate*) G;
    

    change to

    vector G;
    

    and you should do this

    G.push_back(new ANDgate());
    

    or if you use boost use shared_ptrs as vector does quite a lot of copying and naked pointers in a vector can be fatal.

提交回复
热议问题