free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A partial specialization may inherit from an ordinary class
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  C++ Help with Template class program 2011 Vuhelper 0 854 07-23-2011, 05:40 PM
Last Post: Vuhelper
  must have an argument of class or enumerated type Vuhelper 0 1,501 06-11-2011, 06:46 PM
Last Post: Vuhelper
  C++ access private data members in another class Vuhelper 0 1,999 06-07-2011, 08:26 PM
Last Post: Vuhelper
  why we use class in C++ May 2011 ? Vuhelper 0 2,464 05-29-2011, 05:57 PM
Last Post: Vuhelper
  Is it possible to make data type array which act as java Class Object in dev c++ 2011 Xpert 0 2,592 05-12-2011, 09:00 PM
Last Post: Xpert
  A partial specialization may inherit from a complete specialization? Actually I did n saneha 1 1,901 05-02-2011, 06:44 PM
Last Post: Vuhelper
  What is the concept of having the data member of the same class within it? i.e. class saneha 1 2,258 05-02-2011, 05:54 PM
Last Post: Vuhelper
  A data member can be member of any class oject or any particular or there can be any saneha 1 2,214 05-02-2011, 04:50 PM
Last Post: Vuhelper
  In aggregation we use a pointer e.g. like chair object in a room class saneha 1 2,577 05-02-2011, 04:48 PM
Last Post: Vuhelper
  What is difference b/w child class and parent class saneha 1 2,139 05-02-2011, 04:44 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support