I didn't know what this error means
The error is : New types may not be defined in
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include<iostream>
using namespace std;
class opOverClass
{
friend ostream& operator<<(ostream&, const opOverClass&);
friend istream& operator>>(istream&, opOverClass&);
public:
opOverClass operator+(const opOverClass&)
;
bool operator==(const opOverClass&) const;
opOverClass(int i = 0, int j = 0);
private:
int a;
int b;
}
opOverClass::opOverClass(int a, int b)
{
a = 0;
b = 0;
}
opOverClass opOverClass::operator+
(const opOverClass& right) const
{
opOverClass temp;
temp.a = a + right.a;
temp.b = b + right.b;
return temp;
}
bool opOverClass::operator==(const opOverClass& right) const
{
return(a == right.a && b == right.b);
}
int main()
{
opOverClass myClass(5, 6);
cout << 5 + 6;
}
|
New types may not be defined in a return type
Line 16: Missing ;
.
Line 9/23: const
doesn't match.
Thanks coder777 that semicolon helped a lot.
I am now dealing with new other errors now.
Lines 6-7: Your operators are private. That's going to make them impossible to use outside your class.
Line 11: i and j are not members of your class.
Lines 19-20: You're setting the arguments to 0, not the class members. You probably want something like this:
1 2 3 4
|
opOverClass::opOverClass(int a_arg, int b_arg)
{ a = a_arg;
b = b_arg;
}
|
Topic archived. No new replies allowed.