M
Magnus Jonneryd
I've been having some fun with templates and ran in to the following:
template<typename T = int>
class A{
public:
A(): a(0)
{}
protected:
int a;
};
template<typename T = int>
class B: public A<T>{
B(){
a = 1; //*
}
};
If i try to compile this i get a message telling me that "a" is undeclared
but if i change the row (*) to:
this->a
all is well.
Is this due to the fact that the compiler doesn't generate any code for
the template until it is called explicitly? If it is so isn't it odd
that the compiler doesn't realize that "a" is a member of a super class
and then initialize it when I try to assign it a value in a derived class?
Thanks in advance.
template<typename T = int>
class A{
public:
A(): a(0)
{}
protected:
int a;
};
template<typename T = int>
class B: public A<T>{
B(){
a = 1; //*
}
};
If i try to compile this i get a message telling me that "a" is undeclared
but if i change the row (*) to:
this->a
all is well.
Is this due to the fact that the compiler doesn't generate any code for
the template until it is called explicitly? If it is so isn't it odd
that the compiler doesn't realize that "a" is a member of a super class
and then initialize it when I try to assign it a value in a derived class?
Thanks in advance.