Initializer List In C++

  Рет қаралды 26,355

CppNuts

CppNuts

6 жыл бұрын

JOIN ME
-----
KZfaq 🎬 / @cppnuts
Patreon 🚀 / cppnuts
COMPLETE PLAYLIST
------------
C++ Tutorial For Beginners: • Introduction To C++
STL (Standard Template Library): • STL In C++
ThreadIng In C++: • Multithreading In C++
Data Structures: • Data Structure
Algorithms: • Binary Search
Design Patterns: • Factory Design Pattern...
Smart Pointers: • Smart Pointer In C++
C++14: • Digit Separator In C++
C++17: • std string_view in C++...
C++ All Type Casts: • static_cast In C++
INTERVIEW PLAYLIST
------------
C++ Interview Q&A: • Structural Padding & P...
C++ Interview Q&A For Experienced: • How delete[] Knows How...
Linked List Interview Questions: • Find Kth Node From Bac...
BST Interview Questions: • Search Element In Bina...
Array Interview Questions: • Reverse An Array
String Interview Questions: • Check String Is Palind...
Bit Manipulation Questions: • Find Set Bit In Intege...
Binary Tree Interview Question: • Invert Binary Tree
Sorting Algorithms: • Bubble Sort
C++ MCQ: • Video
C MCQ: • What printf returns af...
C Interview Questions: • Designated Initializat...
QUICK SHORT VIDEOS
-------------
C++ Short : • C++ Short Videos
C Short : • Shorts C Programming MCQ
What Are All Those Places Where Initializer List Is Must In C++?
• What Are All Those Pla...
In this video we will learn what is the use of member initialiser list in c++ programming language.
There few points about the same as follows:
1. Constructors And Member Initializer Lists C++
2. This is used to initialize data members of classes.
Two ways are there to do this.
1. Using {} this is uniform initialization and should be preferred.
2. Using ()
#cpp #tutorial #programming #coding #computerscience #softwareengineering

Пікірлер: 45
@benjahnz
@benjahnz 4 жыл бұрын
A great tutrial, clear and concise. Thanks!
@maverick7615
@maverick7615 6 жыл бұрын
omg awesome video! you have made everything become crystal clear thanks man!!
@CppNuts
@CppNuts 6 жыл бұрын
You are most welcome dude.. :)
@mba2ceo
@mba2ceo 2 жыл бұрын
thank U !!! - NO 1 has TOLD me that :) {} make a difference
@crazymemes4080
@crazymemes4080 3 ай бұрын
have you ever noticed this initializer list in LEETCODE question if you check linked list question.
@RAMANKUMAR-xl4pr
@RAMANKUMAR-xl4pr 6 жыл бұрын
thanks for your knowledge sir, You made it very simple and easy. Thanks
@CppNuts
@CppNuts 6 жыл бұрын
Thanks dude!!!
@ks-op8pe
@ks-op8pe 2 жыл бұрын
informative and concise. Thx!
@CppNuts
@CppNuts 2 жыл бұрын
Thanks
@justinhendrix3969
@justinhendrix3969 Жыл бұрын
Awesome video
@konstantinrebrov675
@konstantinrebrov675 6 жыл бұрын
Thank you dear sir!
@CppNuts
@CppNuts 6 жыл бұрын
Welcome man!!
@janardhanreddy1180
@janardhanreddy1180 4 жыл бұрын
Awesome bro
@CppNuts
@CppNuts 4 жыл бұрын
Thanks..
@charmingcat494
@charmingcat494 2 жыл бұрын
Hi Rupesh, I am using this textbook and a piece of code has me confused and you are the only person I could think of to ask. It seems like an object is being initialized within a function inside a class. is this possible? here is the code snippet below: void addInterest(int rate, int divisor) //function within DollarAmount class { DollarAmount interest { //DollarAmount is class name (is interest an object of DollarAmount?) (amount * rate + divisor / 2) /divisor }; //is this an initialization of interest? add(interest); } the book i am using is deitel c++ how to program and this is the example class given in chapter 5.
@sallaklamhayyen9876
@sallaklamhayyen9876 2 жыл бұрын
thank you
@CppNuts
@CppNuts 2 жыл бұрын
Welcome
@DFsdf3443d
@DFsdf3443d 5 жыл бұрын
but what if your member variable is an aggregate, wont it use aggregate initialization then? (which does allows narrowing - as far as i understand) im very confused about this whole initializer_list and aggregate initialization thing im sorry if this is completely wrong
@thilakraj4207
@thilakraj4207 Жыл бұрын
sir could you explain the use of '(int)x' which you used in the program?....I am not aware of that.
@CppNuts
@CppNuts Жыл бұрын
It’s called typecast.
@yc2158
@yc2158 6 жыл бұрын
Do we have any specific name for the " : " which is used for initializing data members?
@yc2158
@yc2158 6 жыл бұрын
I have to tell this "U R THE BEST". U made it simple n easy.😍👍
@CppNuts
@CppNuts 6 жыл бұрын
As you already be knowing, it is collon, and thats the syntax for writing initializer list.
@CppNuts
@CppNuts 6 жыл бұрын
Thank you so much.. :)
@bensalemmohamedabderrahman5844
@bensalemmohamedabderrahman5844 4 жыл бұрын
how can i initialize an array of objects when its private using the initialize list?
@dokodiaries
@dokodiaries 4 жыл бұрын
@CppNuts I think you are using sublime text how to setup it for ubuntu
@CppNuts
@CppNuts 4 жыл бұрын
I cannot explain it here, try Google and I am sure you will get. It`s pretty common
@priteeshneema1574
@priteeshneema1574 4 жыл бұрын
Thank You so Much Sir!! I DO HAVE ONE DOUBT: @5:01 u said {x=a} is assignment and x{a} is Initialisation. But when we do {x=a} doesnt it also perform the same operation as initialisation?
@indlamaheshkumarreddy9376
@indlamaheshkumarreddy9376 4 жыл бұрын
it is initialisation using assignment operator
@aniketahir5578
@aniketahir5578 4 жыл бұрын
no..when object is constructed, compilers fills x with 0/garbage....later on the assignment is done x = a. Initialization list reduces one step...It directly initializes member with value when object is constructed.
@abrarulhaqshaik
@abrarulhaqshaik 2 жыл бұрын
@@aniketahir5578 good comment. everything is clear now, thanks :)
@aniketahir5578
@aniketahir5578 2 жыл бұрын
@@abrarulhaqshaik great to know
@joelcurtis562
@joelcurtis562 4 жыл бұрын
Why use a member initializer list at all? It seems like the way you initialized the member variable x to start with was very intuitive and natural. This way just seems unnecessarily complicated, so I am wondering what is the payoff of having to learn a whole new syntax when a more familiar one seems to work just fine?
@CppNuts
@CppNuts 4 жыл бұрын
Hi Joel, good that you asked, here is the link where i have explained what are the different places where you will use initializer list. kzfaq.info/get/bejne/rNN9frt92qrLiYU.html
@bhupeshpattanaik7150
@bhupeshpattanaik7150 3 жыл бұрын
Where is that video that was mentioned to be in description, I found too many playlist links but no video link
@CppNuts
@CppNuts 3 жыл бұрын
Please mention what video?
@bhupeshpattanaik7150
@bhupeshpattanaik7150 3 жыл бұрын
@@CppNuts pls check this timestamp 6:31
@CppNuts
@CppNuts 3 жыл бұрын
kzfaq.info/get/bejne/rNN9frt92qrLiYU.html
@bhupeshpattanaik7150
@bhupeshpattanaik7150 3 жыл бұрын
@@CppNuts thanks .... 😊😀
@mapradnardev
@mapradnardev 2 жыл бұрын
when i use curely braces Base(int a):x{a} it is throwing error.Using curely braces instead of paranthesis is compiler dependent or what?
@CppNuts
@CppNuts 2 жыл бұрын
Yes upgrade to new compiler.
@samchau8011
@samchau8011 3 жыл бұрын
There is no link in the description where initializer list has to be used! please post it!
@CppNuts
@CppNuts 3 жыл бұрын
Thanks Added in description. kzfaq.info/get/bejne/rNN9frt92qrLiYU.html
@videofountain
@videofountain 4 жыл бұрын
Is this the class constructor member initializer list? Perhaps the name of video should be changed. It was clear to hear you differentiate between initialization and assignment.
@CppNuts
@CppNuts 4 жыл бұрын
Initializer list is used to initialize data members.
Recursion In C++
7:49
CppNuts
Рет қаралды 7 М.
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 24 МЛН
World’s Largest Jello Pool
01:00
Mark Rober
Рет қаралды 102 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
This Pointer In C++
12:22
CppNuts
Рет қаралды 33 М.
Member Initializer Lists | C++ Tutorial
23:10
Portfolio Courses
Рет қаралды 8 М.
What is the Difference Between a Pointer and a Reference C++
7:58
Paul Programming
Рет қаралды 426 М.
Static Data Member And Static Member Function In C++
17:19
CppNuts
Рет қаралды 51 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Virtual Function In C++
15:08
CppNuts
Рет қаралды 34 М.
Destructors in Programming: Practical Demonstration
20:10
CodeBeauty
Рет қаралды 31 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 144 М.
Union In C++
11:30
CppNuts
Рет қаралды 11 М.
Inline Function In C++
17:45
CppNuts
Рет қаралды 30 М.