P
PengYu.UT
The following shows the source code and the error message(from
g++-3.3). I wrote two assignment operator. One is for the same type
case, the other one is for different type case. I'm wondering why it
doesn't work. The error line is marked with comments in the source
code.
Thanks,
Peng
/* main.cc */
template <typename U>
class A{
public:
A() { }
A &operator=(A &that) {
_internal = that._internal;
}
template <typename V>
A &operator=(V &that) {
_internal = that.get_internal();
}
private:
U _internal;
};
int main(int argc, char *argv[])
{
A<int> a;
A<double> b = a;//error
}
/* error message */
g++-3.3 -g -I/usr/local/include/clapack/ -c -o main.o main.cc
main.cc: In function `int main(int, char**)':
main.cc:19: error: conversion from `A<int>' to non-scalar type
`A<double>'
requested
make: *** [main.o] Error 1
g++-3.3). I wrote two assignment operator. One is for the same type
case, the other one is for different type case. I'm wondering why it
doesn't work. The error line is marked with comments in the source
code.
Thanks,
Peng
/* main.cc */
template <typename U>
class A{
public:
A() { }
A &operator=(A &that) {
_internal = that._internal;
}
template <typename V>
A &operator=(V &that) {
_internal = that.get_internal();
}
private:
U _internal;
};
int main(int argc, char *argv[])
{
A<int> a;
A<double> b = a;//error
}
/* error message */
g++-3.3 -g -I/usr/local/include/clapack/ -c -o main.o main.cc
main.cc: In function `int main(int, char**)':
main.cc:19: error: conversion from `A<int>' to non-scalar type
`A<double>'
requested
make: *** [main.o] Error 1