Declare And Initialize An Array Of Objects | C++ Tutorial

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thank you, exactly what I was trying to figure out! Now I know how to initialise an array of objects and call their constructor with parameters for each element!

rudy
Автор

I have learned more in this tutorial, than in two semesters of c++ programming. Thank you so much !

Time-pysv
Автор

If you can't change/want to change the constructor, just use malloc(): Square *squares =
and iterate through with calling the constructor:
for(int i = 0; i<N; i++)
{
squares[i] =
}

ylulnlulsYx
Автор

To extend this, following are also possible,

Square arr1[3] = {
{1, "red"},
{2, "blue"},
{3, "green"}
};

or,

Square arr2[3] = {
{1, "red"},
{}, // default initialized
{3, "green"}
};

or,

Square arr3[3] = {
{1, "red"},
// rest default initialized.
};

avinashthakur
Автор

alright, the ability to call different constructors in a single array definition is pretty cool

adamloepker
Автор

We Appreciate your efforts! Keep making these videos

OCEAN-fcwl
Автор

Brilliant!!!! Learnt a hell of a lot here…

dwivedys
Автор

Hey man, I just subscribed to your channel, I think this channel is underrated. You should have more subscribers given your amazing content👍🏼

Just want to ask,
Im a CS student, and I dont recall being taught this on my programming courses. How is it usually used in real-life program (in workspace), because I assume you wouldn't call functions of an object manually one by one, so something like this would be used in a real-life work. Can you explain how objects are made in real programs?

techademy
Автор

Hahaha (turns to wracking sobs)... I just dug through enough layers of lame, low-content CRAP made by inept wafflers in love with the sound of their own voices to match the kilometres of sediment on the ocean floor, before finally landing here. This array of objects with exactly this kind of attribute control is what I've just spent several hours mucking around trying to build. Thanks for laying it out clearly and succinctly, pitched exactly right for people who need to use it in real projects. ☑ Obviously I'm now subbed, especially since you didn't start the video with THAT ubiquitous, brainless liking and subbing prod, lmao. No wonder there are only 24 of us here; real content is far too dense and bland for the comfort levels of the typical lightweight consumer. 😂

lucasgroves
Автор

Hi.. wonderful explanation. I have a doubt if we have a array of larger rows like square[100]. How can we declare user defined constructor for that?

guruprasaathpushparaj
Автор

Excellent video. Thank you. Here’s a question. Supposing that the array of objects had more space to store other objects. How would I push new objects into the array after the array was initialized?

clistinisstanislawski
Автор

How to make constructor if the input to the object taken by for loop

phoneixacademy
Автор

why is there an error at 4:20 and no error at 6:00`?

framo_official
Автор

how to take input from user in this case !

Dipits_Learning_Point
Автор

why we can't declare an intialize an array inside a class in c++. Please explain I appreciate it.

daredevil
Автор

WHEN WE USE CLASSES IN C++ IN SOLVING A PROBLEM AND HOW TO KNOW WHERE SHOULD WE HAVE TO USE IT . WHAT IS NEED OF OOPS IN C++ WHERE WE USE IT AND SHOULD WE HAVE TO USE OOPS CONCEPT IN EVERY PROGRAM WHAT DIFF OCCURS WHEN PROBLEM SOLVED IN C, AND C++? PLEASE REPLY😃😃😃😃

satyad