Buckys C++ Programming Tutorials – 45 – Member Initializers

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

25 responses to “Buckys C++ Programming Tutorials – 45 – Member Initializers”

  1. Roy Maina Avatar

    bucky did you create sololearn.com and if not why are they copying your tutorials without rights??

  2. Sergio Montesinos Apaza Avatar

    thanks men, you save my life.

  3. Ayush Katoch Avatar

    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.

  4. Zeeshan Malik Avatar

    what is void sally::print()

  5. Pratik Raj Avatar

    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. László Nagy Avatar

    I hate Scott who learned at treehouse…..

  7. Hassan Khan Avatar

    I remember the last 30 seconds!

  8. bujashaka Avatar

    there is a way, have full screen recording and not a cropped one.

  9. Pavan Avatar

    And guess what, you didn't hear a "pretty cool huh?!"in this tutorial. 😛

  10. Dole Pole Avatar

    Honestly, what a STUPID syntax.

  11. Shaheen Ahmed Avatar

    why are the variables initialised in private?

  12. Sebastian Ceblano Avatar

    Would it still work if I input:

    Sally::Sally(int a, int b) {

    regVar = a;
    constVar = b;

    }

  13. srihari sridhar Avatar

    Why cant initialize in the constructor??? like this..

    MyClass::MyClass(int a , int b){
    num=a;
    constnum=b;
    }

  14. MegaRandall2011 Avatar

    Bucky, I know this may seem obvious but for that long line that wouldn't fit on your screen this code would have prevented that:

    void Bella::print(){
    cout << "Regular var is: " << regVar << endl;
    cout << "Constant var is: " << constVar << endl;
    }

  15. Perla Ramos Avatar

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

  16. pepe6666 Avatar

    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

  17. creativeKnowledge Mike Avatar

    did everything he said to doo and it say reg var and const var not declared.

  18. creativeKnowledge Mike Avatar

    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?

  19. Mateo Karaga Avatar

    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…

  20. Ayush Sourav Avatar

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

  21. Filip Jančík Avatar

    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
    ;

  22. emeg losota Avatar

    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.

  23. Dante Bañuelos Avatar

    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

Leave a Reply

Your email address will not be published. Required fields are marked *