PDA

View Full Version : A partial specialization may inherit from a complete specialization? Actually I did n



saneha
05-02-2011, 06:43 PM
A partial specialization may inherit from a complete specialization? Actually I did not understand from your lecture and also tell the reason that why it may inherit from complete specialization

A class template may inherit from an ordinary class.? Please explain this

A partial specialization may inherit from an ordinary class. Actually ordinary class has not template type parameter etc..

Vuhelper
05-02-2011, 06:44 PM
A partial specialization may inherit from a complete specialization:
template<class T>
class B<T*> : public A<float *>
{ … };
int main() {
A obj1;
B obj2;
return 0;
}
obj2 type is int* .class B which is a derived class is instantiated for int * type, where its base class is a specialized class (for float*). You can call inherited methods of base class in template class irrespective of the type of the object for which this template class is instantiated. In this case either class B is instantiated for int or for char, it does not matter, but remember that you can call the public and protected methods / members of base class in template class.
A class template may inherit from an ordinary class:

class A {…};
template<class T> class B: public A {…};
int main(){
A obj1;
B obj2;
return 0;
}
obj2 type is B int. class B which is a derived class is instantiated for int type, where its base class is an ordinary class. You can call inherited methods of base class in template class irrespective of the type of the object for which this template class is instantiated. In this case either class B is instantiated for int or for char, it does not matter, but remember that you can call the public and protected methods / members of base class in template class.

A partial specialization may inherit from an ordinary class:
template<class T> class B<T *> : public A { … };
int main() {
A obj1;
B obj2;
return 0;
}
obj2 type is B int*. Class B which is a derived class is instantiated for int* type, where its base class is an ordinary class. You can call inherited methods of base class in template class irrespective of the type of the object for which this template class is instantiated. In this case either class B is instantiated for int or for char, it does not matter, but remember that you can call the public and protected methods / members of base class in template class.