C++ Class template Deriving a Class Template from a Class Template

Description

C++ Class template Deriving a Class Template from a Class Template

#include <iostream>

using namespace std;

template <typename T>
class Base/*from   w w  w .  ja  va2  s  . c o m*/
{
public:
    T a;
};

template <typename T>
class Derived : public Base<T>
{
public:
    T b;
};

void TestInt(Base<int> *inst)
{
    cout << inst->a << endl;
}

void TestDouble(Base<double> *inst)
{
    cout << inst->a << endl;
}

int main()
{
    Base<int> base_int;
    Base<double> base_double;

    Derived<int> derived_int;
    Derived<double> derived_double;

    TestInt(&base_int);
    TestInt(&derived_int);

    TestDouble(&base_double);
    TestDouble(&derived_double);

    return 0;
}



PreviousNext

Related