Buckys C++ Programming Tutorials – 45 – Member Initializers | Video



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

Source

READ ALSO:  Effects of European Civilization on the Indigenous Yoruba Culture

38 Comments

  1. 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

  2. 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

  3. I am constantly getting the error
    " In function main Undefined reference to 'Sally::Sally(int, int)' " since 2-3 videos
    Can someone help?

  4. 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.

  5. 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?

  6. 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)
    }
    ////////////////////////////////////////////////////////

  7. 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

  8. 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?

  9. 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…

  10. –> Word Wrap Setting in CodeBlocks <–
    – Go to Edit Menu
    – Then Go To Editor Tweaks Option
    – And Select Word Wrap.
    thanks for ur tutorials bucky.

  11. 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
    ;

  12. 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.

  13. 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

  14. ||=== 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???

Comments are closed.