My book is asking me to add two functions to my existing class that return the respective values and its asking me to make them have the same return values and signature, I'm not sure I understand the question can someone explain it to me and why does the compiler not let me overload the getthedatamembertwo function?
You are not permitted to create functions that differ ONLY in return type. How could the compiler know which one you meant to call if that's the only difference?
1 2
int getTheDataMemberTwo(){return theDataMemberTwo;}
float getTheDataMemberTwo(){return theDataMemberTwo;}
When the compiler sees you try to call one of these: ObjectOne.getTheDataMemberTwo(); how could it know which function you meant?
1 2
int theDataMemberTwo;
float theDataMemberTwo;
And this. Variables with the same name. How is the compiler meant to know which one you mean when you try to use one?