+ 2
Help with private function
So I can easily make public functions. But I’m having trouble with private functions here. I was trying to create a private function to later call with an object along with my other public functions. https://code.sololearn.com/coKMEAfLCS63/?ref=app
5 Réponses
+ 1
cout wont work because it should put something into the stream. You try to put into the stream the return value of father(), but its void, so it's just wont compile. When you do return father(), you actually return void, but before that the function is called and in writes what it should into the console.
That's a bit crazy way to do things. You can just call a father() method from showfather() like this
https://code.sololearn.com/c6yq96g7jj05/?ref=app
and if you want to make thing a bit more elaborate, you can make father() method not to write into console, but to return a string, which showfather() method would put into console, like this
https://code.sololearn.com/clpO5NarYPE2/?ref=app
0
I fixed it. i changed cout << father() to return father() lol and that worked. why wouldnt the cout work instead of return?
https://code.sololearn.com/cjBSVmfhUQ4s/?ref=app
0
You have maked "father" method privaye then only in your code class can be called
0
so the first fix would be to remove cout and everything after father()
that works
the second fix would be to change
void father()
to
char* father()
thats works as well
wow...that was easy.
0
Дмитро Іванов why did changing void to char * work instead? just trying to get a better understanding