hey, everyone. I am still learning templtes and I have 2 questions:
1-Why is it that all the examples of templates I have seen are about arrays?Is that all templates are used for?
2-after pondering about the above question, I decided to try something else witha template..a generic unction.
However the program just hangs when I run it. Only one object is created(because I always put a sentence in my constructors, to know when an object is created. the sentence appears only once.)
Can someone help me out? Thanks in advance!![
#include<iostream>
#include<string>
using namespace std;
template<class T>
class display{
public:
T dat1,dat2;
display():dat1(0),dat2(0){
cout<<"Display's constructor"<<endl;
}
~display(){
cout<<"Display's destructor"<<endl;
}
T add(T& dat1,T& dat2){
cout<<dat1 + dat2<<endl<<"add() has executed"<<endl;
return dat1+dat2;
}
};
int main()
{
int dati1=34,dati2=60;
string dats1("Tobi is a "),dats2("very good boy");
display<int>intd;
display<string>stringd;
intd.add(dati1,dati2);
stringd.add(dats1,dats2);
return 0;
}
"Show me your code and I will tell you who you are.."-Tkud