Puoi derivare da una classe "zero". Ad esempio:
Codice PHP:
//
// Compiled and tested with:
// i686-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
//
// g++ -Wall -ansi -pedantic main.cpp
//
// output:
// 2
// ciao
//
#include <iostream>
class zero{
public:
virtual void DoIt () = 0;
virtual ~zero (){};
};
template<class LabelType>
class uno: public zero
{
public:
LabelType label;
uno (LabelType theLabel) : label (theLabel) {};
virtual void DoIt (){
std::cout << label << std::endl;
}
virtual ~uno (){};
};
template<class LabelType>
class due: public uno<LabelType>
{
public:
due (LabelType theLabel) : uno <LabelType>(theLabel) {};
virtual ~due (){};
};
class tre : public due<int>
{
public:
tre() : due<int>(2) {};
virtual ~tre (){};
};
int main (){
zero * aZero = new tre;
zero * aOnotherZero = new due <std::string> ("ciao");
aZero->DoIt ();
aOnotherZero->DoIt ();
delete aOnotherZero;
delete aZero;
return 0;
}