A
Adam Nielsen
Hi again,
I've got another question about template specialisation. I would like
to declare some data types in the main template (the "base class") but I
would then like to extend the behaviour with template specialisations.
Unfortunately it seems that when I try this, the specialisation doesn't
get appended to the base template (as happens when you inherit from a
base class), but rather it replaces it completely, for example this code
won't compile:
template <typename T>
class A
{
public:
typedef std::vector<T> V;
//V myVector; // works
};
class A<int>
{
private:
V intVector; // doesn't work
};
I get this error:
'V' is used as a type, but is not defined as a type.
Which implies that the typedef is getting lost. Is there a way around
this? Some sort of class inheritance would probably work, but I'd like
to try avoiding this as it's more for code clarity than anything else
('int' in my example above is actually a complex template instantiation,
so the code can become difficult to read if it's written out in full all
over the place.)
Thanks,
Adam.
I've got another question about template specialisation. I would like
to declare some data types in the main template (the "base class") but I
would then like to extend the behaviour with template specialisations.
Unfortunately it seems that when I try this, the specialisation doesn't
get appended to the base template (as happens when you inherit from a
base class), but rather it replaces it completely, for example this code
won't compile:
template <typename T>
class A
{
public:
typedef std::vector<T> V;
//V myVector; // works
};
class A<int>
{
private:
V intVector; // doesn't work
};
I get this error:
'V' is used as a type, but is not defined as a type.
Which implies that the typedef is getting lost. Is there a way around
this? Some sort of class inheritance would probably work, but I'd like
to try avoiding this as it's more for code clarity than anything else
('int' in my example above is actually a complex template instantiation,
so the code can become difficult to read if it's written out in full all
over the place.)
Thanks,
Adam.