Overloading unary operators

Hello! I was trying to overload unary operatirs ++ and --. You can see the code below. And this is the compiler messege: 12:6: error: expected initializer before 'Base'
Any advice on how to fix this would be welcome. Thank you in advance!

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
// overloading operators
#include <iostream>
using namespace std;

class Base {     
public: 
int x, y, z; 
Base() {x = y = z = 0; } 
Base(int c, int d, int f) {x = c; y = d; z = f; } 
Base operator++();
Base operator--();
}
Base Base::operator++()
{
  x++;
  y++;
  z++;
  return *this;
}
Base Base::operator--()
{
  x--;
  y--;
  z--;
  return *this;
}
int main () {
    Base data(1,2,3);
    ++data;
    cout<<data.x<<","<<data.y<<","<<data.z<<endl;
    --data;
    cout<<data.x<<","<<data.y<<","<<data.z<<endl;
  return 0;
}
1
2
3
class Base {
  // members
} ;
Keskiverto, I'm really grateful to you! It was a very primitive mistake, but you helped me a lot. I didn't notice that. Thank you again!
Topic archived. No new replies allowed.