C++ OOP (2020) - What are constructors and class methods? How to use them?

Поделиться
HTML-код
  • Опубликовано: 28 сен 2024
  • In this video, I'm explaining when, why, and how are constructors and class methods used.
    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCpp...
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObj...
    🚀📈💻🔥 My Practical Programming Course: www.codebeauty...
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    Download Visual Assist here: bit.ly/WT-CB
    I use it to enhance the performance, features, and support for C, C#, and C++ development in Visual Studio.
    Download Ultra Edit here: bit.ly/UE_CB
    It is a powerful, secure text editor designed specifically for programmers.
    ☕ If you've found my content helpful and would like to support me, you now have the option to buy me a coffee or a cookie! It's a small gesture of gratitude that means a lot to me and helps me keep creating free educational videos for you. You can use the link below to make a contribution: bit.ly/CodeBea...
    However, please don't feel obligated to do so. I appreciate every one of you, and I will continue to share valuable content with you regardless of whether you choose to support me in this way. Thank you for being part of the Code Beauty community! ❤️😇
    Introduction to OOP - • C++ OOP - Introduction...
    If you are a beginner in C++, check out my "C++ for beginners" course: • C++ FOR BEGINNERS (202...
    "C++ functions" course:
    • C++ FUNCTIONS (2020) -...
    Follow me on other platforms:
    Instagram 📸 - / truecodebeauty
    Twitter 🐦- / truecodebeauty
    ******INITIAL CODE IS IN THE COMMENTS******

Комментарии • 340

  • @CodeBeauty
    @CodeBeauty  4 года назад +40

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    #include
    #include
    using namespace std;
    class RUclipsChannel {
    public:
    string Name;
    string OwnerName;
    int SubscribersCount;
    list PublishedVideoTitles;
    };
    int main()
    {
    RUclipsChannel ytChannel;
    ytChannel.Name = "CodeBeauty";
    ytChannel.OwnerName = "Saldina";
    ytChannel.SubscribersCount = 1800;
    ytChannel.PublishedVideoTitles = {"C++ for beginners Video 1", "HTML & CSS Video 1", "C++ OOP Video 1"};
    cout

    • @Павелик-з4е
      @Павелик-з4е 4 года назад

      Welcome me 😍 friend.

    • @CodeBeauty
      @CodeBeauty  4 года назад +1

      @@Павелик-з4е Hahaha, welcome! 🤗

    • @Павелик-з4е
      @Павелик-з4е 4 года назад

      @@CodeBeauty 🇰🇿

    • @CodeBeauty
      @CodeBeauty  4 года назад

      Wow, I'm glad to see that people are watching me on the other side of the world! Қош келдіңіз! ☺️

    • @Павелик-з4е
      @Павелик-з4е 4 года назад

      @@CodeBeauty менің RUclips каналыма үлкен рахмет, мен сізді көргеніме қуаныштымын.🙂

  • @kathrinlahner5620
    @kathrinlahner5620 2 года назад +70

    Usually, I don't comment...but after three years of programming and finally understanding constructors I want to say THANK YOU🌸- and I mean it!! Your explanations are comprehensible and finally there's a way for me to understand what I'm supposed to do with all that code. Coffee bought☕

    • @CodeBeauty
      @CodeBeauty  2 года назад +4

      Thank you so much 🥰💞

  • @TimelyEnlightenment
    @TimelyEnlightenment Год назад +46

    I've read plenty of c++ ebooks and they are very comprehensible, but your way of explaining class and objects in this video is way more comprehensive. Starting with simple way of creating class and then how you can create multiple classes without having to repeat the same codes. This is better than how I learn it in college. AMAZING 👏

  • @joyceosas7793
    @joyceosas7793 10 месяцев назад +19

    Three years already and your videos are still very useful. God bless you, Saldina

  • @aubreymmotong9550
    @aubreymmotong9550 2 года назад +3

    i used to dread C++ until i started following this channel. Teaching is a s skill. Thank you so much...

  • @dev.antunes
    @dev.antunes 3 года назад +7

    I understood 100%. Now I see the meaning of the constructors. *Thank you so much, Saldina.*

    • @CodeBeauty
      @CodeBeauty  3 года назад +3

      Great! I'm happy to help 🤗

  • @yuanyuan23191212
    @yuanyuan23191212 2 года назад +15

    Thanks Saldina. It would be great if you could also cover destructors, virtual destructors, delete, and related dynamic memory parts when you have time in future.😀

  • @mayureshharihar2557
    @mayureshharihar2557 2 года назад +2

    Feeling very lucky after found this channel 😇

  • @melody.-.1839
    @melody.-.1839 7 месяцев назад +1

    Thank you so much for explaining this, my professor in college blew through this and it's immensely helpful to see your examples! Going to watch this whole series of videos

  • @StephenElDrago
    @StephenElDrago 3 года назад +1

    watched five different videos about classes and your video made it all click, thank you. you saved my life

  • @rudradev3873
    @rudradev3873 2 года назад +6

    Thank you so much for these gems. Helps me to become exponentially better in programming, maybe I'll top my branch this semester.

    • @CodeBeauty
      @CodeBeauty  2 года назад +3

      Wow, good luck, I'm so glad to hear that top level students are learning from my channel 😃😃

  • @subratadas9772
    @subratadas9772 2 года назад +1

    everyone who do such works,give time ,and bring such content is worthy to be appreciated,plz bring data structures too.

  • @mikegenco9646
    @mikegenco9646 Год назад +1

    One of my favorite songs is Baker Street by Gerry Rafferty. A side note on terminology, I have heard the different arguments in an overloaded function called the function's signature.

  • @belloemmanuel4878
    @belloemmanuel4878 8 месяцев назад

    I like that you adopt this "show me the problem with something" before you introduce the new concept that was meant to be the solution.

  • @miaflorida9410
    @miaflorida9410 9 месяцев назад

    I really wanna thank you because i am really struggling with C++ and your instructions are so clear and your verbalism, the way you talk is also great and understandable. All these coding videos there's always some guy who is indian and speaking with a terrible accent so i can't really understand from them sometimes (english is my second language) you saved me really! subscribed

  • @phungat6621
    @phungat6621 3 года назад

    I have to admit that your video is absolutely clear. Thats why I choose to watch your video despite language difference

  • @erenjaeger__1
    @erenjaeger__1 Год назад +1

    THANK U MAM 🙇‍♀️
    LOVE FROM INDIA❤️

  • @WintaRussom
    @WintaRussom 3 года назад +4

    Thanks a lot! I love your explanation and the way you've used relatable class's name and objects ☺️

  • @heeDeer
    @heeDeer 2 года назад

    I dont usually comment on videos but this really helped. Im very new to programming and struggling alot and this video really helped me understand constructors. THANK YOU!

  • @MatthewJohnson-yc7nx
    @MatthewJohnson-yc7nx 2 года назад +1

    I appreciate your hardwork to make these videos at 3am.
    I have had more success with your videos gaining practice and understanding foreign concepts.

  • @epj_oficial
    @epj_oficial Год назад +2

    My favorite song is Circe's Spell from Kalidia band. Kisses from Brazil, Saldina...

    • @CodeBeauty
      @CodeBeauty  Год назад +1

      Muitos beijos para o Brasil 🥰❤️

  • @roberte.o.speedwagon114
    @roberte.o.speedwagon114 3 года назад

    Aaaaa taj naglasak mogu prepoznati u snu. Inace odlicni snimci i nadam se da ces nastaviti sa njima od mene samo reci hvale i podrske

  • @jasnarmstrng
    @jasnarmstrng Год назад +1

    So far, so good 🙂
    ...
    Song: Where I am - Freetown Collective.

  • @mudmaster9965
    @mudmaster9965 2 года назад +14

    I am really new with programming. The way you teach by comparing old methods with new one is remarkable !
    It make me understand about why it happened and why it matter
    Thank you

  • @sushimuppet4
    @sushimuppet4 2 месяца назад

    I love ur videos!! It'll really help me with my finals🌸

  • @hamzehidris6340
    @hamzehidris6340 2 года назад

    Thank you very much your videos are very helpful! I stopped go to my classes in uni and instead I'm watching your videos and learning much more!

  • @raykos4257
    @raykos4257 2 года назад +2

    Great tutorial! So clear and well paced!!!

  • @clakker9412
    @clakker9412 Год назад +1

    I love you so much really thankkk you!!!!!!!!!!!!!!!!! finally i found someone who teaches really REALLY WELLLL

  • @gagef4101
    @gagef4101 Год назад +1

    Little late but my favorite song is Beast of Burden by The Rolling Stones. Thanks for your videos!

  • @michelmoncada22
    @michelmoncada22 Год назад +1

    my TA recommended you THank you Belen and thank you it was really helpful

  • @erende44
    @erende44 2 года назад +1

    best explanation I found so far, thanks!

  • @kiwi-sw9kn
    @kiwi-sw9kn Год назад

    Does she have a video showcaseing her Setup so I can have thoose shortcuts aswell in my compiler ?

  • @nicolascrespo4643
    @nicolascrespo4643 2 года назад +1

    Thank you! Much appreciated. This series are great!

  • @ΔανιήλΤριανταφύλλης

    Thank you for this video, I think you understand where I am having difficulties better than any other coding channel so I always look for your videos first now haha

  • @FlyGamingChannel
    @FlyGamingChannel 3 месяца назад

    Why do you not use initialiser lists in your constructors?

  • @Coolpanda77454
    @Coolpanda77454 11 месяцев назад

    can we add the video title in the constructor as one of the elements that takes string?

  • @user-zj9pq5xc7x
    @user-zj9pq5xc7x Год назад +1

    excellently explained. thank you!!

  • @diogopocas7943
    @diogopocas7943 Год назад

    Thank you so much. I had so much trouble understanding this in class

  • @Selinzik_CEO
    @Selinzik_CEO 3 месяца назад

    The song is called "Paradise by Lil Uzi Vert"....Please listen to it when you're driving and there's a sunset.

  • @spiderpig993
    @spiderpig993 3 года назад +2

    can you explain what the push_back() function does? Is that a predefined function? Very helpful vids btw.

    • @zoejackson7184
      @zoejackson7184 2 года назад

      Idk if this is any help now but push_back() appends whatever is in the parenthesis to the end of the string

    • @amortalbeing
      @amortalbeing 2 года назад

      @@zoejackson7184 push_back is one of the methods in the list class. remember you had a list of strings where you defined it as list sth.
      now sth is a list of strings and when you want to add something to that list, you have several options, one of which is a method called push_back.

  • @gaborm4767
    @gaborm4767 Год назад

    It would be nice to show how we can use a class from different translation units. How to write header file and cpp file in this case.

  • @ziam4393
    @ziam4393 3 года назад +1

    What can I say other than my jaws only dropped in amazement at how you easily delivered this.

  • @Farjanamoon-no7ok
    @Farjanamoon-no7ok Год назад +1

    you are really a great tutor

  • @bushraw66
    @bushraw66 2 года назад

    that is exactly what I was looking for, very helpful. thank you so much

  • @zainatta7544
    @zainatta7544 8 месяцев назад

    Thank you so much. I finally understand constructors

  • @liquidred257
    @liquidred257 3 года назад +2

    Is there an advantage to using "list" instead of perse "PublishedVideoTitles string[100]" (so I guess an array)?
    Also I really like rainbow in the dark by Dio

  • @vicky404_vicky
    @vicky404_vicky 4 года назад +1

    Clear explanation, pls do more videos in c++

  • @athanusri8337
    @athanusri8337 Год назад

    miss saldina.. you made my day .. thank u so much

  • @rahultom4310
    @rahultom4310 6 месяцев назад

    Can't we call a list inside a constructors? If yes why do you call PublishedVedioTitles as an attribute of the object?

  • @ednakazuya12
    @ednakazuya12 3 года назад

    My favorite bands, Mathew Sweet, NOFX, Face to Face, Tokyo Jihen, and Third Eye Blind

  • @louayal1907
    @louayal1907 2 года назад

    here's an arabic song you may want to listen to
    Fayrouz - Sa'alouny El Nas / فيروز - سألونى الناس

  • @shubhanshsingh
    @shubhanshsingh Год назад

    Brilliant, Excellent, thanks so so muchh !!!!

  • @МаксимМихайлов-п5е
    @МаксимМихайлов-п5е 2 года назад

    Very clear && easy to understand, thank you!

  • @ankursingh9214
    @ankursingh9214 3 года назад +1

    Thank you my new mam for teaching c++ in very simple and easy way.
    I am from India .so, Language becomes more barrier for me but in your case I didn't feel like this
    due to your easy way of teaching and making the things related us by giving perfect example
    once again Thank you so must...

  • @jianhe
    @jianhe 2 года назад

    you explained why very well. Thanks.

  • @CesarAugustoRL
    @CesarAugustoRL 3 года назад

    You are an excellent teacher, thank you very much!

  • @madalinavarga3337
    @madalinavarga3337 3 года назад

    Hi! Amazing tutorials,i watched only two ,for the moment, and i really like its.

  • @firstlylast5890
    @firstlylast5890 8 месяцев назад

    understood, but, a light theme, really!

  • @SophoniaLetsoalo-w3p
    @SophoniaLetsoalo-w3p 2 месяца назад +1

    Magnificent 🎉

  • @RainMoneyProductions
    @RainMoneyProductions Месяц назад +1

    my favorite song is My Demise by RAINMNY also Decompression by RAINMNY is pretty decent too i love them so much haha xD

  • @harry8912
    @harry8912 2 года назад

    What if you want the user to input everything in the constructor instead of pre filling everything out?

  • @ceren6312
    @ceren6312 Год назад

    It's litterally years later but I really like Taylor Swift- Sweet Nothing and You're on Your Own Kid. Also Hikari Are from Burnout Syndromes. By the way I LOVE YOUR VIDEOS YOU ARE GREAT AT THIS ehehehheh

  • @ksanavengsar4050
    @ksanavengsar4050 Год назад +2

    Rammtein ❤ thank you so much for video

  • @lhaellor
    @lhaellor 2 года назад

    how to make a function which returns a value? for example a function in a class which returns the value of the area of a rectangle or any other calculations and etc? any recommended videos?

  • @sammy949
    @sammy949 3 года назад

    Thanks a lot! Your example choose very good.

  • @Mahm00dM0hanad
    @Mahm00dM0hanad 10 месяцев назад

    Well :) my favorite song called I’m free it’s a soundtrack of a movie “spirit” and the singer is non other the legendary Brain Adams

  • @carelsoney4480
    @carelsoney4480 2 года назад

    so are methods, like void GetInfo, similar to functions?

  • @krishna_3406
    @krishna_3406 6 месяцев назад

    you should deserve more subscribers ☺

  • @Straycatpopy
    @Straycatpopy 2 месяца назад +1

    i love carry you by ruelle

  • @MateuszAdamczyk
    @MateuszAdamczyk 3 года назад

    You should promote good practices from the begining, for example: initializing object’s fields after colon and not in the constructor’s body.

  • @blub.lubber5171
    @blub.lubber5171 Год назад +1

    How you gonna casually drop a Scorpions song I've never heard before? Good tune

  • @trippinjohn367
    @trippinjohn367 9 месяцев назад

    One of my favorite songs is Decks Dark by Radiohead rn

  • @saberjan9238
    @saberjan9238 2 года назад +1

    My favorite song is "Shamoon Ismail - rung"

  • @elsafernandatorresferia886
    @elsafernandatorresferia886 3 года назад

    Thanks for the videos from México!
    Quick question: A class method is like a function inside a class?

  • @Zabi281
    @Zabi281 Год назад

    Very good video 📸 deserve likes and subscription.

  • @abdirizakomar8279
    @abdirizakomar8279 3 года назад +2

    Please do python videos too.

  • @99Anonymous999
    @99Anonymous999 Год назад

    what does this mean string videoTitle : PublishedVideoTitle ?? Please explain.

  • @eminbaybarstimurstudent3802
    @eminbaybarstimurstudent3802 3 года назад

    Such a great video. It was a great practice.

  • @IAmIshanSaxena
    @IAmIshanSaxena 4 года назад +3

    Well my favorite songs are "Sugar" by Maroon 5 and" We Don't Talk Anymore" by Charlie Puth

  • @BrothonAlone
    @BrothonAlone 3 года назад

    hi teacher my favorite song is Take me to your heart and Don't leave me alone.

  • @limelemonada
    @limelemonada 5 месяцев назад

    A literal lifesaver

  • @AsakuraDantes
    @AsakuraDantes 2 года назад +1

    Sweet home alabama is my fav song

  • @polatonur6476
    @polatonur6476 5 месяцев назад +1

    I have a midterm tomorrow and let's see if you can save me. :D

  • @gadgeting6039
    @gadgeting6039 4 месяца назад +1

    Thanks!

  • @the_muhammadali_7338
    @the_muhammadali_7338 3 года назад

    Can we create array of an object, for defining /creating more objects?

  • @7401kb
    @7401kb 2 года назад +1

    I appreciate the way of teaching and great hardwork to prepare such a perfect videos. Excellent work by CodeBeauty!

  • @jakkdlaw
    @jakkdlaw 3 года назад +5

    to be honest you put my teachers to shame

    • @cmgeolo
      @cmgeolo 3 года назад

      I can’t agree with you more. I question what I’m paying for.

  • @zakmukhtar7521
    @zakmukhtar7521 Год назад

    my favorite songs are eatfrommydinner - white stripe and frou frou - guitar song ! yay!

  • @ESteveMcLaughlin
    @ESteveMcLaughlin 3 года назад

    In the class RUclipsChannel, I added brackets to the end of "int SubscribersCount{};". I was getting an error -
    Warning C26495 Variable 'RUclipsChannel::SubscribersCount' is uninitialized. Always initialize a member variable (type.6). It fixed the error and I am debugging in x64 if that might make a difference?
    Another great video series. Thanks Everett

  • @ashrsfsiliman452
    @ashrsfsiliman452 3 года назад +1

    Thank you for your great job

  • @xlxs1
    @xlxs1 4 года назад +1

    Is it ok if RUclipsChannel::PublishedVideoTitles was vector instead of list?

    • @CodeBeauty
      @CodeBeauty  4 года назад +3

      Hi 🤗
      Vectors and lists internally are very different data collections. List stores elements at the non-contiguous memory locations and the vector uses contiguous memory.
      This code here is very simple, so you can use both, but there are a couple of things to consider when it comes to using lists vs vectors if you want to upgrade this code.
      Inserting and deleting data from a list is very efficient because it is not going to shift any elements in the memory, just swap a couple of pointers.
      In vectors, however, inserting and deleting at the start or in the middle will shift all the elements. And if you want to add an element at the end, and there is no enough memory, then a bigger contiguous memory chunk will be allocated, and all your vector elements will be copied there.
      Another thing to consider is accessing elements at random positions. Since vector is using contiguous memory, it is going to be much more cost-effective to access an element at position 100, than if you use list, because it stores elements in noncontiguous memory locations, you'll have to iterate through fist 99 elements to be able to access your 100th element.
      This is a topic for a whole video, but I hope that I helped at least a little bit. 😊

  • @luisortega5636
    @luisortega5636 3 года назад

    Beautiful! My favorite song is Time from Pink Floyd! Great Video!

  • @akanguven114
    @akanguven114 Год назад

    May the Force be with you.

  • @정민강-r1s
    @정민강-r1s 3 года назад +1

    Chain Gang of 1974 - Sleepwalking. That's also the ending song of GTA5. You should love it, I hope ;)

  • @gvberhveh
    @gvberhveh 2 года назад

    A šta je sa destruktorima bona?

  • @PrasadPatil-eg1lo
    @PrasadPatil-eg1lo 3 года назад +1

    Woah its great thnx saldina✌🏻

  • @jgbcjgbc2323
    @jgbcjgbc2323 4 года назад +2

    Can you make the text in your videos a little bigger?

    • @CodeBeauty
      @CodeBeauty  4 года назад

      I already have a couple of filmed videos, but I can do that for future ones. 😊

  • @yasirfazli6083
    @yasirfazli6083 3 года назад

    Wow great keep it up
    I really love your videos

  • @kurukhibrovnik5886
    @kurukhibrovnik5886 4 года назад +1

    Hi, ( sorry for my english ), first all i wish congratulation for your initiative for this course! But i have a question , why your attribute are public and not private ? usally the attributes are private and they are access with getter and setter ( information hiding ) why you don't created getter and setter. e.g. your method "getInfo" should be modified like
    cout

    • @CodeBeauty
      @CodeBeauty  4 года назад +4

      Benvenuto! 🇮🇹
      Yep, that is correct, but not everyone is going to understand that without proper explanation.
      "Data hiding" principle that you're talking about is called encapsulation, and I made a video about that as well.
      It is a continuation of this video.
      Here is the link: ruclips.net/video/a8ZB-TPB6EU/видео.html
      Btw, your English is good! 😊

  • @loool87871
    @loool87871 3 года назад

    Great, thanks for your videos and efforts, I have a question, at 7:22 you said that in case of declaring new object from the class we have to give it some parameters like Name, ...., so what shall be done just to declare a new object, before knowing anything about it, just like int x, is there something for that?, Many thanks in advance