I want write an simple demo, but it compile failed, I can't find the reason.
#include <iostream>
#include <vector>
#include <list>
using namespace std;
template <
typename T,
template <typename W> typename Container = std::vector
>
class myclass
{
public:
Container<T> myc;
public:
void func();
myclass()
{
for (int i = 0; i < 10; ++i)
{
myc.push_back(i);
}
}
};
template <
typename T,
template <typename W> typename Container
>
void myclass<T, Container>::func()
{
cout << "good!" << endl;
}
int main()
{
myclass<int, vector> mylistobj2;
mylistobj2.func();
return 0;
}
the compile reason is that
tmp.cpp: In function ‘int main()’:
tmp.cpp:100:30: error: type/value mismatch at argument 2 in template parameter list for ‘template<class T, template<class W> class Container> class _nmsp1::myclass’
100 | _nmsp1::myclass<double, list> mylistobj2;
| ^
tmp.cpp:100:30: note: expected a template of type ‘template<class W> class Container’, got ‘template<class _Tp, class _Alloc> class std::__cxx11::list’
tmp.cpp:101:13: error: request for member ‘func’ in ‘mylistobj2’, which is of non-class type ‘int’
101 | mylistobj2.func();