Facebook – https://www.facebook.com/TheNewBoston-464114846956315/
GitHub – https://github.com/buckyroberts
Google+ – https://plus.google.com/+BuckyRoberts
LinkedIn – https://www.linkedin.com/in/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/
Twitter – https://twitter.com/bucky_roberts
Proudly WWW.PONIREVO.COM
Comments are closed.
Just few more tutorials to go
How he used that private class member to print the output
In one of his previos videos he said that we can't access the private class directly.but its working..help plz
can anyone please tell me that although the code is running fine how he used a constant variable in a non-constant function?
So, "Encapsulation" can be done with this then? I'm getting mixed up now!
Damn perfect tutorial. Yes the syntax is pretty fkd up.
Why can you access private ?
if you get a "No such file in the directory" error, make sure you don't have your object set to the same name as a c++ keyword! My class was named "dog" so I named my object "do", I got an error because "do" is the same as do, a separate c++ keyword. I set the name to "dogobject" and it worked
I am constantly getting the error
" In function main Undefined reference to 'Sally::Sally(int, int)' " since 2-3 videos
Can someone help?
At 5:52 , Bucky says that Sally so( )is a constructor but as i remember a constructor always has the same name as that of the class.Can anyone explain?
What if we want to do a type check before assigning value in constructor????
Thank you 🙂
bucky did you create sololearn.com and if not why are they copying your tutorials without rights??
thanks men, you save my life.
Cant we do it like this ?
Sally :: Sally(int a , int b){
regVar = a ;
constVar = b;
}
Even here we are just intializing the variables, since Sally() is executed the moment an obj is created i dont think it will make a difference.
what is void sally::print()
as regVar is not a constant variable, why we defined this before the paranthesis , can we only define consVar in that manner and regVar under parenthesis?
well explained!!
I hate Scott who learned at treehouse…..
I remember the last 30 seconds!
there is a way, have full screen recording and not a cropped one.
And guess what, you didn't hear a "pretty cool huh?!"in this tutorial. 😛
Honestly, what a STUPID syntax.
why are the variables initialised in private?
Would it still work if I input:
Sally::Sally(int a, int b) {
regVar = a;
constVar = b;
}
Why cant initialize in the constructor??? like this..
MyClass::MyClass(int a , int b){
num=a;
constnum=b;
}
In the class under under "private: ", can't you just say reg Var = 3 . and modify it in the class function[Sally::Sally(int a, int b)]
///////////////////////////////////////////////////////
Like in Sally.h
public:
Sally(int , int);
private:
int regVar;
const int constVar;
///////////////////////////////////////////////////////
in Sally.cpp
Sally::Sally (int a, int b) : constVar(b) {
regVar = a;
}
///////////////////////////////////////////////////////
and in main.cpp
main() {
Sally so(3, 87)
}
////////////////////////////////////////////////////////
why are ya defining private variables in the header?
surely that should be defined in the .cpp file.
the idea of the header according to previous videos was that the publicly exposed stuff was in there.
this is the first time we've seen variables declared in the header and i don't understand why
did everything he said to doo and it say reg var and const var not declared.
Just a question and what i think , I see this and then realize after all I've learned so far what the hell am I learning. What can I do with all this im looking for game design but i don't know the first thing?
Hello,
Error is inside of main, and i create object:
Mateo ma(4 ,50);
ma.print();
I get error at number 4 its say: cannot access private member declared in class 'Mateo'
I just do as in video, just rename my variable and class.
Can't find solution, help…
–> Word Wrap Setting in CodeBlocks <–
– Go to Edit Menu
– Then Go To Editor Tweaks Option
– And Select Word Wrap.
thanks for ur tutorials bucky.
You can just press enter after a "<<" and continue typing in the next line. The compiler ignores blank spaces in the code.
EDIT: Just as an example, the two codes are both working:
1/
cout << "Hi << endl;
2/
cout
<<
"Hi"
<<
endl
;
word wrap? use somewhere in your line and press enter. It helps you to continue your code on the next line without using another cout.
Does the function that initializes variables need to be named the same thing as the class?
Otherwise, I don't see how this could be written:
Sally so (3, 87);
because it doesn't specify the function within the class that initializes the variables
hmm.. why not just assign regvar = a?
||=== Build: Debug in yyyy (compiler: GNU GCC Compiler) ===|
C:UsersatikDownloadscodeblockyyyymain.cpp||In function 'int main()':|
C:UsersatikDownloadscodeblockyyyymain.cpp|8|error: no matching function for call to 'Sally::Sally(int, int)'|
C:UsersatikDownloadscodeblockyyyymain.cpp|8|note: candidates are:|
C:UsersatikDownloadscodeblockyyyySally.h|8|note: Sally::Sally()|
C:UsersatikDownloadscodeblockyyyySally.h|8|note: candidate expects 0 arguments, 2 provided|
C:UsersatikDownloadscodeblockyyyySally.h|5|note: Sally::Sally(const Sally&)|
C:UsersatikDownloadscodeblockyyyySally.h|5|note: candidate expects 1 argument, 2 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Can anyone help me out???
that's how to word wrap without anything special.
cout << "regular var is " << regVar << " and constant "
<< "variable is " << constVar << endl;