So if classes are a valid data type then...?

Started by
9 comments, last by Drevay 20 years, 3 months ago
quote:Original post by Drevay
Heh, Nervo - I'm reading about returning objects in functions in my book - so that's why the author returned an object in that way.





I was checking through all my posts from a few days ago and I guess I missed your response drevay. I just want to point out in that code something that you might/might not have noticed. When I returned sample as a reference that was fine, but the way the function was called it wasn't actually necessary to return a value:

void input(sample& ab){  char instr[80]; cout << "Enter a string: "; cin >> instr; ab.set(instr);}int main(){ sample ob;input(ob); //when the function returns this call is not going to assign to anythingob.show(); return 0;}


As the comment says, it is not strictly needed here and so I changed the return to void. However, it does not hurt anything to do so because you can do something like this:

if(input(ob) == something) { execute something; }

But thats your choice.


[edited by - nervo on January 20, 2004 7:41:49 AM]
Well, R2D22U2..

This topic is closed to new replies.

Advertisement