lizhuo wrote:
Quote:
hi all:
I reading "C++ Templates: The Complete Guide "
Part II: Templates in Depth
he write:
>
template<typename T>
class B {
public:
enumE{e1=6,e2=28,e3=496};
virtual void zero(E e = e1);
virtual void one(E&);
};
>
template<typename T>
class D : public B<T{
public:
void f() {
typename D<T>::E e; // this->E would not be valid syntax
this->zero(); // D<T>::zero() would inhibit virtuality
one(e); // one is dependent because its argument
} // is dependent
};
>
who can tell me ,"this->E would not be valid syntax "
why?
The operator-is called the member selection operator. It is used to
select a member (non-static method or variable) of an object. Thus
this->E is invalid, as E is not the name of a method or variable of
class D. As Victor pointed out, this->B::one would be legal, as B:: in
this expression is used to denote the name scope of class B for looking
up the member one (which would mean that you want to invoke the method
'one' as it is defined for class B).
Regards,
Stuart