"Gil" <br**************@hotmail.com> wrote in message
news:ad**************************@posting.google.c om...
trying to use a template in a vector, in Visual Studio 6 on Windows
2000
#include <vector>
using namespace std;
template <typename T>
class AnyValue {
T val;
public :
AnyValue(T inv)
{
val = inv;
}
};
class ValuesObject {
int count;
vector<AnyValue, allocator<AnyValue> > ivo; // error occurs here!!
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyValue av)
{
vector<AnyValue, allocator<AnyValue> >::iterator iter = ivo.end();
ivo.insert(iter, av);
}
};
I'm getting :
error C2955: 'AnyValue' : use of class template requires template
argument list
Can anyone see what I am doing wrong?
As far as C++ is concerned, is what I am doing correct? Is this a
compiler issue with Visual C++?
You have defined AnyValue as a template class but you have not provided the
template arguments.
All you have to do is to replace "AnyValue" in class ValuesObject something
like "AnyValue<int>".
Else if you do not want a concrete type like int make ValuesObject class
also as a template class and provide the
template argument for AnyValue.See the code below.That compiles without any
error in the Visual C++ 6.
#include <vector>
using namespace std;
template <typename T>
class AnyValue {
T val;
public :
AnyValue(T inv )
{
val = inv;
}
};
template <typename U> class ValuesObject {
int count;
vector<AnyValue<U>, allocator<AnyValue<U> > > ivo;
public :
ValuesObject() {}
~ValuesObject() {}
int getCount()
{
return count;
}
void addValue(AnyValue<U> av)
{
vector<AnyValue<U>, allocator<AnyValue<U> > >::iterator iter =
ivo.end();
ivo.insert(iter, av);
}
};