The
operator Plus()
and
operator Minus()
operators are not arithmetic operators but cast (conversion) operators, so they are fine (enhzflep is wrong here). They each return a newly constructed value of the requested type.
The issue is simply that you're using each of them before they're fully defined.
To solve this.
1. Add the following line before the Minus() class:
class Plus;
This declares that there is a class called
Plus
that will be defined later.
2. Replace the definition of
operator Plus()
in class
Minus
with the following:
operator Plus();
This declares the cast operator without defining it.
3. After the Plus class, add the definition of operator Plus() as follows:
inline Minus::operator Plus() {
return Plus();
}
This defines the cast operator outside the body of the class, after the needed definitions have been seen.
The key idea here is that a declaration and definition of a function (or variable, or class) can be separated, allowing you
to avoid the need for the two functions to be fully defined. This is common in C++, as source code is processed from the
top down. To use a function, it must have been declared earlier in the source, or (commonly) in a declaration included from a header.
All those #include statements just substitute their contents directly in the source file - so the declarations contained are
all available to the definitions in your code.
Hope this helps.