I was wondering how I would do this, I have a class called Shape2D with overloaded + and - operators and then I have 2 inherited classes called Circle and Rectangle.
The overloaded operators just add the protected variable area defined in the Shape2D class together. I looked at the overloading operator tutorial section and made it exactly like that. I'll post part of my code so you guys can look over it and help me a little bit.
I had it like the overloaded - operator first but I kept getting a "Shape2D is not an accessible base of Circle" or something along those lines and then I overloaded it accepting either a circle or rectangle thinking that was the problem but now it's saying "declaration of 'operator+' as non-function".
Hope I provided enough information, looking for help quick because it's due in an hour. I'd still like to know what's wrong if I can't get it done in time though. Thanks.
and then in the main function I'm declaring a seperate Shape2D class called ShA that holds the temp.area value returned from the overloaded operators, it's like this (CirA and CirB being Circle objects):
This is most likely because you have no forward declaration of either of the classes you're using in the operator overloads. The compiler isn't very picky, but it at least needs to know what objects and functions exist, even if it can't find any definitions. Therefore, all you need to do is add a very basic declaration of the classes you're using, and the compiler should assume that you will fill in methods and properties at some point later in the code.
1 2 3 4
class Circle; // The compiler now knows these exist
class Rectangle; // No further information is required yet
// ...Continue the definition of your classes, as you had them