list of polymorphic objects

后端 未结 3 830
星月不相逢
星月不相逢 2020-12-03 19:09

I have a particular scenario below. The code below should print \'say()\' function of B and C class and print \'B says..\' and \'C says...\' but it doesn\'t .Any ideas.. I a

3条回答
  •  心在旅途
    2020-12-03 20:03

    list::iterator it; B bObj; C cObj; A *aB = &bObj; A *aC = &cObj; listOfAs.insert(it,*aB);

    Do you not need to initialize "it" ? I believe you should do it = listOfAs.begin(); before starting to insert.

提交回复
热议问题