The program below compiles in VS 2010, but not in a recent version of Mingw. Mingw gives me the error "conversion from int to non-scalar type 'tempClass(it)' requested". Class "it" is just a simple class to use in the template for the purpose of illustration.
#include <iostream>
#include <string>
using namespace std;
template <class T>
class tempClass{
public:
T theVar;
tempClass(){}
tempClass(T a){
theVar = a;
}
/* tempClass <T> & operator = (T a){
(*this) = tempClass(a);
return *this;
}
*/
};
class it{
public:
int n;
it(){}
it(int a){
n = a;
}
};
int main(){
tempClass <it> thisOne = 5; // in MinGW gives error "conversion from int to non-scalar type 'tempClass(it)' requested"
cout << thisOne.theVar.n << endl; // in VS 2010 outputs 5 as expected
}
Commenting in/out the assignment operator portion doesn't seem to make a difference - I didn't expect it to, I just included it because I also hope to do things like tempClass <it> a = 5; a = 6;
, in case this is relevant to the answer.
My question is, how can I get this syntax to work as desired?