J
jim.brown
The attached code implements a test class to show an error in
overloading operator=. This code works on Windows with Visual
Studio and simpler cases work with gcc 3.3.2 on Solaris 9.
On Windows, operator= gets called twice and I'm not sure whay
that is.
This fails on Solaris with:
In function 'int main(int, char**)'
error: no match for 'operator=' in 't2 = TestCL::getTestCL()()'
error: candidates are : TestCL& TestCl:
perator=(TestCL&)
I have seen this message when there is something ambiguous and
more than one candidate are listed. Since my code runs on Windows
it has to be something subtle about some default function which
gcc doesn't do or something.
Does anyone see something I did wrong?
Jim
_______________________________________________________________
long globalint = 0; // global for TestCl
class TestCl{
public:
TestCl(); // Constructor
~TestCl(); // Descructor
TestCl& operator=(TestCl& right); // assignment overload
TestCl(const TestCl& cc); // Copy constructor
TestCl getTestCl();
long data;
}; // end TestCl
TestCl::TestCl(){ // Constructor
data = ++globalint;
}
TestCl::~TestCl(){ // Descructor
data = (-data);
}
TestCl::TestCl(const TestCl& cj){ // Copy constructor
data = 100*(++globalint);
}
TestCl& TestCl:
perator=(TestCl& right){ // assignment overload
if (this != &right){
data = right.data+7;
}
return *this;
}
TestCl TestCl::getTestCl(){
TestCl res;
return res;
}
int main (int argc, char **argv){
try{
TestCl t1;
TestCl t2 = t1.getTestCl();
t2 = t1.getTestCl();
} catch( ... ){
std::cout << "Error" << std::endl;
}
}
overloading operator=. This code works on Windows with Visual
Studio and simpler cases work with gcc 3.3.2 on Solaris 9.
On Windows, operator= gets called twice and I'm not sure whay
that is.
This fails on Solaris with:
In function 'int main(int, char**)'
error: no match for 'operator=' in 't2 = TestCL::getTestCL()()'
error: candidates are : TestCL& TestCl:
I have seen this message when there is something ambiguous and
more than one candidate are listed. Since my code runs on Windows
it has to be something subtle about some default function which
gcc doesn't do or something.
Does anyone see something I did wrong?
Jim
_______________________________________________________________
long globalint = 0; // global for TestCl
class TestCl{
public:
TestCl(); // Constructor
~TestCl(); // Descructor
TestCl& operator=(TestCl& right); // assignment overload
TestCl(const TestCl& cc); // Copy constructor
TestCl getTestCl();
long data;
}; // end TestCl
TestCl::TestCl(){ // Constructor
data = ++globalint;
}
TestCl::~TestCl(){ // Descructor
data = (-data);
}
TestCl::TestCl(const TestCl& cj){ // Copy constructor
data = 100*(++globalint);
}
TestCl& TestCl:
if (this != &right){
data = right.data+7;
}
return *this;
}
TestCl TestCl::getTestCl(){
TestCl res;
return res;
}
int main (int argc, char **argv){
try{
TestCl t1;
TestCl t2 = t1.getTestCl();
t2 = t1.getTestCl();
} catch( ... ){
std::cout << "Error" << std::endl;
}
}