Hi everybody. I have a problem deleting a template class and I would be very grateful if anyone can help! Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <vector>
template <typename T> class DataType
{
public:
private:
std::vector<T> mVector;
};
int main()
{
DataType <class T> * dataType = ( DataType <class T> * ) new DataType <int>;
delete dataType;
return 0;
}
|
If I comment out the vector then it compiles fine. But when it is there, g++ complains. It seems that it cannot figure out the type of the vector. Here is the error message:
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_vector.h: In destructor `std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = T, _Alloc = std::allocator<T>]':
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_vector.h:256: instantiated from `std::vector<_Tp, _Alloc>::~vector() [with _Tp = T, _Alloc = std::allocator<T>]'
example.cc:16: instantiated from here
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_vector.h:106: error: invalid use of undefined type `struct T'
example.cc:15: error: forward declaration of `struct T'
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_construct.h: In function `void std::__destroy_aux(_ForwardIterator, _ForwardIterator, __false_type) [with _ForwardIterator = T*]':
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_construct.h:152: instantiated from `void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = T*]'
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.4/../../../../include/c++/3.4.4/bits/stl_vector.h:256: instantiated from `std::vector<_Tp, _Alloc>::~vector() [with _Tp = T, _Alloc = std::allocator<T>]'
Thanking you in advance!