M
Meph
I know the following is supposed to work because struct AAA has a
constructor taking an int.
#include<iostream>
struct AAA {
AAA(int n): value(n) {}
int value;
};
bool operator==(const AAA& p, const AAA& q)
{
return p.value==q.value;
}
int main()
{
AAA x(1);
std::cout<<(1==x)<<std::endl;
return 0;
}
Can anyone tell me the part of the standard that disallows the
templated version of the above, like so:
#include<iostream>
template<class T>
struct AAA {
AAA(int n): value(n) {}
int value;
};
template<class T>
bool operator==(const AAA<T>& p, const AAA<T>& q)
{
return p.value==q.value;
}
int main()
{
AAA<int> x(1);
std::cout<<(1==x)<<std::endl;
return 0;
}
Why isn't a compiler required to convert 1==x to AAA<int>(1)==x, as in
the non-template case?
Thanks,
Meph
constructor taking an int.
#include<iostream>
struct AAA {
AAA(int n): value(n) {}
int value;
};
bool operator==(const AAA& p, const AAA& q)
{
return p.value==q.value;
}
int main()
{
AAA x(1);
std::cout<<(1==x)<<std::endl;
return 0;
}
Can anyone tell me the part of the standard that disallows the
templated version of the above, like so:
#include<iostream>
template<class T>
struct AAA {
AAA(int n): value(n) {}
int value;
};
template<class T>
bool operator==(const AAA<T>& p, const AAA<T>& q)
{
return p.value==q.value;
}
int main()
{
AAA<int> x(1);
std::cout<<(1==x)<<std::endl;
return 0;
}
Why isn't a compiler required to convert 1==x to AAA<int>(1)==x, as in
the non-template case?
Thanks,
Meph