Classes Part 22 - Curly brace versus parenthesis and std::initializer_list| Modern cpp Series Ep. 59

  Рет қаралды 8,314

Mike Shah

Mike Shah

Күн бұрын

Пікірлер: 50
@RakVish
@RakVish 6 ай бұрын
Pheewwwww. This was exactly what was needed. A concise but complete explanation about how the two versions work. Especially that last point showing that the parameterized constructor gets called when the initializer_list version of a constructor does not exist!!
@MikeShah
@MikeShah 6 ай бұрын
Cheers!
@AlmondAxis987
@AlmondAxis987 Жыл бұрын
As a self-taught c++ programmer, this was really useful. I always wondered how libraries used curly braces for Container classes like rectangles, points, or RGBA colors. Thanks!
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@utkrystal45
@utkrystal45 7 ай бұрын
Well, I will surely recommend this video to my friends starting out with classes and want to have a deep understanding of initializer_list and curly braces. So, well taught by you, Sir!
@MikeShah
@MikeShah 7 ай бұрын
Cheers!
@lemuener
@lemuener 7 ай бұрын
Thanks Mike for the Course I'm learning a lot of new things , very easy to understand your explanations... Thanks a lot.
@MikeShah
@MikeShah 7 ай бұрын
You are most welcome!
@dwolrdcojp
@dwolrdcojp 2 жыл бұрын
Clear and easy to understand example. Thanks as always!
@MikeShah
@MikeShah 2 жыл бұрын
You are most welcome, thank you for the continued kind words!
@dhanushs1802
@dhanushs1802 2 жыл бұрын
Very neatly explained as always. Thank You.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers thank you for the kind words!
@propov1802
@propov1802 2 жыл бұрын
Hey, I got a question. At 2:27 Why do you print them by reference on primitive types? Wouldn't it be faster to print them by value?
@MikeShah
@MikeShah 2 жыл бұрын
For primitive types (i.e. a 4-byte int) you're probably right. :)
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
Thanks Mike for answering. Looking back at the code with your answer in mind, i have just realized that no member assignment was done in the constructor with parenthesis and if i am not wrong no elements have been saved(written) to m_data. How can the u object be constructed with parenthesis in this case then?
@MikeShah
@MikeShah 2 жыл бұрын
m_data will just be uninitialized. You should otherwise initialize it to some default value in the constructor if desired. In a few lessons I'll show how to do this with a delegate constructor. 😉
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
I am eager to know how it's done . Thank you ever so much
@sallaklamhayyen9876
@sallaklamhayyen9876 2 жыл бұрын
great teacher + valuable content = thank you so much
@MikeShah
@MikeShah 2 жыл бұрын
Cheers! Thank you for the kind words!
@TheOldRoots
@TheOldRoots Жыл бұрын
Do the curly braces only prevent narrowing, or any type conversion ? Like I understand why "int a{1.4}" would give an error since you are losing information in the conversion, but would float a{3} also give an error?
@MikeShah
@MikeShah Жыл бұрын
The braces require type to match, so would need to do a{3.0f}; for instance.
@quoctrieu2413
@quoctrieu2413 2 жыл бұрын
Thank you very much !!! Thanks to your video i found the solution to assigne values to the obj of array (myseft-defined datatype) in this way: array obj = {val1, val2, ...}
@MikeShah
@MikeShah 2 жыл бұрын
You are most welcome!
@joebosah2727
@joebosah2727 2 жыл бұрын
Can’t get enough Carry on regardless Merci beaucoup
@MikeShah
@MikeShah 2 жыл бұрын
Derien mon ami! Cheers!
@brajrajsingh1001
@brajrajsingh1001 5 ай бұрын
can anyone comment about the original souce code of various standard classes in c++ like class vector, class string , etc
@MikeShah
@MikeShah 5 ай бұрын
They're certainly interesting to look at and learn some tricks from -- and over time they're very useful to study more to understand exactly how things work. The STL's goal is to be portable, performant, and generic, so that may impact readability of the code however :)
@blaisofotso3439
@blaisofotso3439 2 жыл бұрын
Hallo Mike, why cant we print our data when we use parentheses? @12:39 / 15:52
@MikeShah
@MikeShah 2 жыл бұрын
Parenthesis use the constructor ;) So m_data does not have any elements to print out.
@manuvaad
@manuvaad 2 жыл бұрын
Thank you so much. Your lessons and talks are awesome as always!
@MikeShah
@MikeShah 2 жыл бұрын
Cheers, thank you for the kind words!
@reptilicusrex4748
@reptilicusrex4748 2 жыл бұрын
Great explanation. Thanks.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@7denis71
@7denis71 2 жыл бұрын
Awesome! Your video lessons are awesome! :) Thank you for your doing this!
@MikeShah
@MikeShah 2 жыл бұрын
Thank you for the kind words!
@dolphin2954
@dolphin2954 2 жыл бұрын
Great video. Thanks.
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@ThislsYusuf
@ThislsYusuf 2 жыл бұрын
I got a stack-use-after-scope on address error when using AddressSanitizer. Is this a compiler bug? (It runs well without fsanitize) Thanks for the instruction!
@MikeShah
@MikeShah 2 жыл бұрын
Hard to know without seeing the code, do you have a timestamp in the video?
@ThislsYusuf
@ThislsYusuf 2 жыл бұрын
​@@MikeShah Thanks for the reply, it s the code I have after finishing the video. Hope pasting the code here isn't too cumbersome #include #include struct UDT{ UDT(std::initializer_list data) : m_data(data) { std::cout
@MikeShah
@MikeShah 2 жыл бұрын
@@ThislsYusuf Works fine for me on g++ and clang++, perhaps a compiler bug if you're on msvc? Try pasting in compilerexplorer.com and see if it works for some other compilers.
@ThislsYusuf
@ThislsYusuf 2 жыл бұрын
@@MikeShah On it. Thanks!
@hani_yt678
@hani_yt678 2 жыл бұрын
Thank you for the video , keep it up !
@MikeShah
@MikeShah 2 жыл бұрын
Absolutely!
@rango1049
@rango1049 Жыл бұрын
thanks Mike
@MikeShah
@MikeShah Жыл бұрын
Cheers!
@meganfoxyou
@meganfoxyou 2 жыл бұрын
Very helpful, thank you!
@MikeShah
@MikeShah 2 жыл бұрын
Cheers!
@SuperCoolHandle94
@SuperCoolHandle94 2 жыл бұрын
Thanks alot
@MikeShah
@MikeShah 2 жыл бұрын
You're most welcome!
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
C++ Weekly - Ep 348 - A Modern C++ Quick Start Tutorial - 90 Topics in 20 Minutes
20:47
C++ Weekly With Jason Turner
Рет қаралды 35 М.
Member Initializer Lists | C++ Tutorial
23:10
Portfolio Courses
Рет қаралды 10 М.
Member Initializer Lists in C++ (Constructor Initializer List)
8:37
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 861 М.
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН