+ 4
I am pulling my hairs out can someone help me
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);
+ 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();
+ 2
im bout to give up on this
+ 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’
+ 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.
+ 2
Zeke Williams im really trying to get this but cant grasp it
https://code.sololearn.com/cLbgxVIbNpk4/?ref=app
+ 1
ok so i changed it but it is still giving me compilation error
+ 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.
+ 1
but thanks
+ 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.
+ 1
+ 1
You should go through the object oriented section again to refresh your memory.
https://code.sololearn.com/c8z77tQrG0ig/?ref=app
+ 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:
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;
};
0
well, im out