I just finished watching some videos of template and I think I am missing some concepts. Why doesn't the constructor get called, or why the object is not created when the constructor is not overloaded with a desired data-type? Since I am writing the <int>
doesn't the compiler know I am going to be dealing with an int?
template <class T>
class Generic {
T var;
public:
Generic(){cout << "ctor called " << endl;}
//Generic (T v) {var = v;}
};
int main () {
Generic<int> generic1();
}
Can't I create an object like this and then modify the value of T var through a setter? Why should I need an overloaded constructor e.g. Generic<int> generic1(9);
?