void dooperation() { cout<<x+y; }
#include <iostream> using namespace std; template<class T> class calculator { protected: T x; T y; public: calculator(T m,T n) { x=m; y=n; } virtual void dooperation()=0; }; template<class T> class addition: public calculator<T> { public: addition(T m,T n):calculator<T>(m,n) { } void dooperation() { cout<<x+y; } }; int main() { addition<int> add(3,4); calculator <int>* ptr; ptr=&add; ptr->dooperation(); }
void dooperation() { cout << this->x + this->y; }
public: const T& getX() { return x; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)