[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
What am I missing?
From: |
Matt Yule |
Subject: |
What am I missing? |
Date: |
Fri, 11 Jan 2002 08:32:53 -0500 |
I'm new to C++ in general and g++ in particular. I keep getting the
same type of
error and can't figure out why. The test program below along with the
error I get when
I try to compile it is typical of the problems I've been having. I have
a Borland C++ compiler
on my PC at home which compiles the same program with no errors or
warnings. Am I missing something obvious? Any help would be greatly
appreciated.
ERROR:
test.cpp: In function `int main()':
test.cpp:35: no match for `TestClass& = TestClass' operator
test.cpp:21: candidates are: TestClass TestClass::operator=(TestClass&)
PROGRAM:
#include <iostream>
using namespace std;
class TestClass {
public:
TestClass(int i);
TestClass(const TestClass ©me);
TestClass operator=(TestClass &original);
TestClass operator+(TestClass &addme);
int data;
};
TestClass::TestClass(int i){
data=i;
}
TestClass::TestClass(const TestClass ©me){
data=copyme.data;
}
TestClass TestClass::operator=(TestClass &original){
data = original.data;
return *this;
}
TestClass TestClass::operator+(TestClass &addme){
TestClass temp(0);
temp.data = data + addme.data;
return temp;
}
int main(){
TestClass ob1(4), ob2(2);
ob2 = ob1 + ob2;
cout << "Object 2 contains " << ob2.data << endl;
return 0;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- What am I missing?,
Matt Yule <=