Это видео недоступно.
Сожалеем об этом.

Singleton Design Pattern | C++ Example

Поделиться
HTML-код
  • Опубликовано: 2 июн 2022
  • How to implement the singleton design pattern in C++. This implementation is thread-safe and uses lazy instantiation. Source code: github.com/por.... Check out www.portfolioc... to build a portfolio that will impress employers!

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

  • @alexplaytop
    @alexplaytop 4 месяца назад +2

    Easy understand even for Juniors, thx MAN...

  • @dev-evandro
    @dev-evandro Год назад +4

    Very very well explained! Explained clearly and at an ideal speed of speech. It is very pleasant to listen to and you can directly comprehend the content conveyed. Thanks for the great video!

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

      Thank you for sharing such kind positive feedback, and you're very welcome! 🙂

  • @senemyildiz.
    @senemyildiz. Год назад +1

    Great and well explained video. Thank your for your sharing. I hope you could add the rest of design patterns. It would be very helpful.

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

      You’re welcome! :-) I do eventually want to cover more design patterns in C++.

  • @ghazalamirrashed9119
    @ghazalamirrashed9119 Год назад +4

    I have checked out a lot of sources and channels but none of them explained as good as this one. can you by any chance make a data structures series in c++? it would be bomb!

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

      I'm glad you enjoyed the video! :-) And hopefully one day I can do a data structures series in C++.

  • @bimblebom
    @bimblebom 7 месяцев назад

    Your lessons are really brilliant! Short, terse, succinct with clear examples. Are you on Patreon?

  • @Victor-fl8ex
    @Victor-fl8ex 2 года назад +1

    good stuff Kevin!

  • @amortalbeing
    @amortalbeing 4 месяца назад

    great job ❤

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

    Great video. Are there any plans to do any more design pattern videos? I would love to see more

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

      I would love to cover all the classic design patterns in C++ and Python. Exactly when I'll get to doing more, I'm not sure. :-) This video has started to get some great feedback and viewership over the last while though, which is really encouraging to make more design pattern videos.

  • @deltanine1591
    @deltanine1591 4 дня назад

    Thanks bro

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

    Thanks ❤ keep it up & plz post other important design patterns tooo

    • @PortfolioCourses
      @PortfolioCourses  9 месяцев назад +1

      You’re welcome! :-) What other design patterns would you like to see covered?

    • @CSEAJMALAKRAMS
      @CSEAJMALAKRAMS 8 месяцев назад +1

      @@PortfolioCourses decorator, command patterns and some important design patterns.. And Thanks for the response 🙌💫

    • @PortfolioCourses
      @PortfolioCourses  8 месяцев назад +1

      @@CSEAJMALAKRAMS Thanks for the feedback! 🙂

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

    Thanks for the video...it really helps.:)

  • @Solo6R
    @Solo6R 7 месяцев назад

    Why make the constructor protected instead of private? I always made my singleton class constructors private and have had no issues. Maybe protected is doing something else I don't know?

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

      Not really sure either, constructors aren't inherited so idk.

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

    Hi sir from week I have been following your channel
    Recently I come across why globally pointers allocate space in data segment in memory map..

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

      Thanks for following the channel Rama. Is that a topic you think I should make a video on? Do you have a link to the article or video that you came across? :-)

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

    I have a doubt acc to definition n code; the second creation of object singleton2 should not be correct or possible.
    What is the reason we don’t get any such error?

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

      Making the copy constructor a deleted function is what prevents the Singleton from being copied by using an assignment operator like this :Singleton singletonN = singleton1;. If the copy constructor is not a deleted function, then the assignment statement will be OK, and we will get a copy of the singleton using the default copy constructor.

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

    Thank you 😊

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

    Hello, this is nice example, could you make one video? " Multiton pattern on C++"

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

      That is a great idea for a video, I have added to my list of ideas. :-)

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

      @@PortfolioCourses Ohhhh, thank you very much

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

      @@osnovan7169 You're welcome! 🙂

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

    best, though you hasn't explained the syntax in the multiple deleted operators

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

      In videos on more advanced topics like this I don't always explain certain things due to time constrains. :-)

  • @Victor-fl8ex
    @Victor-fl8ex 2 года назад

    hey Kevin.
    at 4:49, variable singleton1 is also a reference to a Singleton object. But get instance also returns a reference, so you returining a double reference at the end? Im getting kinda confused

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

      The get_instance() function returns an instance, and singleton1 is an instance, so the types make sense. We're not returning a 'double reference' or anything like that.... get_instance() just returns a reference to that static instance variable and singleton1 will then become a reference (i.e. synonym) to that same variable. Reference variables definitely aren't straightforward, maybe this video will b useful: ruclips.net/video/e3DN1RaYVYQ/видео.html.

    • @Victor-fl8ex
      @Victor-fl8ex 2 года назад

      @@PortfolioCourses thanks master

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

      Haha you’re welcome! :-)

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

    What does "= default " do ?

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

      It makes a defaulted function, this video explains the concept: ruclips.net/video/OupyUY7FKUI/видео.html. :-) There is also deleted functions too: ruclips.net/video/-PQRjsX_1i8/видео.html.

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

      @@PortfolioCourses thanks - so default is used when NO Parameters are sent ?

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

      In this example, yes.
      Though this is a very minor point, technically what we pass the function are called "arguments". The "parameters" are the variables that those arguments are set to. So if we have:
      void func(int x) { ... }
      func(5);
      Then x is the parameter and 5 is the argument.