I have the following piece of code where i have genuinely made a syntax mistake:
#include<iostream>
using namespace std;
template<typename Type1,typename Type2>
class Pair{
public:
Type1 first;
Type2 second;
Pair();
Pair(Pair<Type1,Type2>& obj);
};
template<class Type1,class Type2>
Pair<Type1,Type2>::Pair(){
first=Type1();
second=Type2();
}
template<class Type1,class Type2>
Pair<Type1,Type2>::Pair(Pair<Type1,Type2>& obj1){
cout<<"Inside the copy constructor\n";
obj1.first= //THIS IS THE PROBLEMATIC STMNT
}
int main()
{
/* Code here */
Pair<int,int> com1;
//Pair<complex1,complex2> com2(com1);
}
I dont find any compile/run time errors with this program. However if i uncomment the second line in main which calls the copy constructor then it throws a compiler time error. I know that class instatiates according to the types during runtime, but syntax errors like this for sure are checked in a templatized class during compilation stage. Why no compile time error then? I am using VS2008.