C++ Generic Linked List

前端 未结 4 1284
旧巷少年郎
旧巷少年郎 2021-01-29 00:38

For the code below:

#include 
#include 

using namespace std;

class Foo2;
class Foo3;

template 
class Foo1 {
  pub         


        
4条回答
  •  时光说笑
    2021-01-29 01:21

    Despite your assertions to the contrary, the example you've given could be solved with std::list:

    std::list list;
    
    list.push_back(new Foo2());
    list.push_back(new Foo3());
    
    for (std::iterator it = list.begin(); it != list.end(); ++it)
    {
        (*it)->print();
    }
    

    Obviously, there's a potential memory leak here...

提交回复
热议问题