You are viewing a single comment's thread. Return to all comments →
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> #include <string> using namespace std; template<class T1, class T2> class Add{ T1 a; T2 b; public: Add(T1 a, T2 b){ this->a=a; this->b=b; } void concat(){ cout<<a+b<<'\n'; } }; int main() { int n; cin>>n; string type; for(int i=0; i<n;i++){ cin>>type; if(type=="string"){ string f, l; cin>>f>>l; Add<string, string> obj(f, l); obj.concat(); } else if(type=="int"){ int x, y; cin>>x>>y; Add<int, int> obj1(x, y); obj1.concat(); } else if(type=="float"){ float a, b; cin>>a>>b; Add<float, float> obj2(a, b); obj2.concat(); } } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
C++ Class Templates
You are viewing a single comment's thread. Return to all comments →