?
=?gb2312?B?wfXquw==?=
Hi, folks,
I'm running into a question as below:
template<typename T>
class A {
private:
T _a;
public:
A(T t): _a(t) {
}
};
template<typename T>
void operator+(A<T> lhs, A<T> rhs) {
}
int main() {
A<int> obj(5);
int t = 5;
obj + t;
}
When I try to compile the code above under MSVC8, I got the following
errors:
1. error C2784: 'void operator +(A<T>,A<T>)' : could not deduce
template argument for 'A<T>' from 'int'
2. error C2676: binary '+' : 'A<T>' does not define this operator or a
conversion to a type acceptable to the predefined operator
with
[
T=int
]
Any informative reply will be appreciated, thanks in advance.
Best regards,
Liu Hao
I'm running into a question as below:
template<typename T>
class A {
private:
T _a;
public:
A(T t): _a(t) {
}
};
template<typename T>
void operator+(A<T> lhs, A<T> rhs) {
}
int main() {
A<int> obj(5);
int t = 5;
obj + t;
}
When I try to compile the code above under MSVC8, I got the following
errors:
1. error C2784: 'void operator +(A<T>,A<T>)' : could not deduce
template argument for 'A<T>' from 'int'
2. error C2676: binary '+' : 'A<T>' does not define this operator or a
conversion to a type acceptable to the predefined operator
with
[
T=int
]
Any informative reply will be appreciated, thanks in advance.
Best regards,
Liu Hao