+ 4

I am pulling my hairs out can someone help me

https://code.sololearn.com/cEn9To3EuLX2/?ref=app

4th Jul 2018, 4:36 PM
Quadier Mackey
Quadier Mackey - avatar
17 Réponses
+ 3
And just so you know Quadier Mackey , you don't use a colon ':' for return statements. Just space or parentheses: return x; return (x + 5);
4th Jul 2018, 5:11 PM
Zeke Williams
Zeke Williams - avatar
+ 3
Quadier Mackey oh okay! Personally I would make a string variable private, then use a public function to output it. private: string word; public: void output() { cout << word << endl; } // in main object.output();
4th Jul 2018, 5:57 PM
Zeke Williams
Zeke Williams - avatar
+ 2
im bout to give up on this
4th Jul 2018, 4:39 PM
Quadier Mackey
Quadier Mackey - avatar
4th Jul 2018, 5:07 PM
Zeke Williams
Zeke Williams - avatar
+ 2
Ok so to understand this, I had ‘atkincreasedeclaration as the wrong data type. It was return but it should’ve been Void, and add parentheses after it. Then I had to delete the second console out command. Don’t know why but that fixed it. 3rd was in private the atkincreasdeclaration was string when that too should’ve been void. I had that but was vacillating between void or string...idk. I still have more learning to do. but what did you do when you added the atkincreasedeclaration inside the ‘void getatkincrease’
4th Jul 2018, 5:35 PM
Quadier Mackey
Quadier Mackey - avatar
+ 2
Zeke Williams i see but i wanted to learn how to use and call private functions with specific requirements because I like the extra layer of security. like what if i took the public and changed its name to private...how would I access it. thats what this project was.
4th Jul 2018, 5:53 PM
Quadier Mackey
Quadier Mackey - avatar
+ 2
Zeke Williams im really trying to get this but cant grasp it https://code.sololearn.com/cLbgxVIbNpk4/?ref=app
4th Jul 2018, 6:37 PM
Quadier Mackey
Quadier Mackey - avatar
+ 1
ok so i changed it but it is still giving me compilation error
4th Jul 2018, 5:01 PM
Quadier Mackey
Quadier Mackey - avatar
+ 1
oh wow thank you. it started as public then I changed it to private to test my skills and see if i could access it. having trouble understanding what you did still, excuse me.
4th Jul 2018, 5:17 PM
Quadier Mackey
Quadier Mackey - avatar
+ 1
but thanks
4th Jul 2018, 5:17 PM
Quadier Mackey
Quadier Mackey - avatar
4th Jul 2018, 5:35 PM
Quadier Mackey
Quadier Mackey - avatar
+ 1
When you use the cout object to output to the console, you don't need to return anything, so make the function return void. I saw that you made one function private so I used a public function (since you can't call a private one from outside the class) to call the private one. You could just copy and paste what's in the public func into the private one, then just call it from main.
4th Jul 2018, 5:38 PM
Zeke Williams
Zeke Williams - avatar
4th Jul 2018, 5:40 PM
Zeke Williams
Zeke Williams - avatar
+ 1
You should go through the object oriented section again to refresh your memory. https://code.sololearn.com/c8z77tQrG0ig/?ref=app
4th Jul 2018, 6:44 PM
Zeke Williams
Zeke Williams - avatar
+ 1
the only thing i changed was the void type to string type(and a few minor changes here and there). the public calling the private isnt an issue you cant have a void function return a value. you did well by trying out the public and private access specifiers o:
5th Jul 2018, 6:04 PM
Denny
Denny - avatar
0
#include <iostream> using namespace std; class atkpower{ public: string getatkincrease (){ return atkincreasedeclaration(); } private: string atkincreasedeclaration (){ return "increase atk power by 10"; } }; int main() { atkpower atkobject; atkobject.getatkincrease(); cout << atkobject.getatkincrease (); return 0; };
5th Jul 2018, 6:03 PM
Denny
Denny - avatar
0
well, im out
12th Jul 2018, 1:43 AM
Craig Wade