K
Ken Cecka
This is a contrived example to demonstrate a syntax problem I'm struggling
with:
#include <vector>
template <typename T>
class Class
{
};
template <typename T>
class Container
{
public:
typedef Class<T> * ClassPointer;
typedef std::vector<ClassPointer> ClassVector;
typedef ClassVector::iterator ClassVectorIterator;
};
int main(void)
{
return 0;
}
When I compile this code using g++ v3.4.1, I get the following errors:
/home/ceckak/test.cpp:16: error: type `std::vector<Class<T>*,
std::allocator<Class<T>*> >' is not derived from type `Container<T>'
/home/ceckak/test.cpp:16: error: ISO C++ forbids declaration of `iterator'
with no type
/home/ceckak/test.cpp:16: error: expected `;' before "ClassVectorIterator"
If I change the ClassPointer typedef to the following, the error goes away
typedef Class<int> * ClassPointer;
Or if I make Class a regular (non-template) class, the error goes away.
Or if I comment out the iterator typedef, the code compiles without errors.
Can anyone tell me if/how to declare an iterator to a vector of template
pointers?
Thanks in advance for any help!
Ken
with:
#include <vector>
template <typename T>
class Class
{
};
template <typename T>
class Container
{
public:
typedef Class<T> * ClassPointer;
typedef std::vector<ClassPointer> ClassVector;
typedef ClassVector::iterator ClassVectorIterator;
};
int main(void)
{
return 0;
}
When I compile this code using g++ v3.4.1, I get the following errors:
/home/ceckak/test.cpp:16: error: type `std::vector<Class<T>*,
std::allocator<Class<T>*> >' is not derived from type `Container<T>'
/home/ceckak/test.cpp:16: error: ISO C++ forbids declaration of `iterator'
with no type
/home/ceckak/test.cpp:16: error: expected `;' before "ClassVectorIterator"
If I change the ClassPointer typedef to the following, the error goes away
typedef Class<int> * ClassPointer;
Or if I make Class a regular (non-template) class, the error goes away.
Or if I comment out the iterator typedef, the code compiles without errors.
Can anyone tell me if/how to declare an iterator to a vector of template
pointers?
Thanks in advance for any help!
Ken