Easily the most concise explanation on this topic on YT. You answered every single one of my questions. Thanks a lot and I hope you get more recognition for your awesome work!
Insanely underrated video lectures you are giving out for free, I am going to college soon and this has been a great help, will share with my friends(if i make any)👍
Okay that's cool, but what if I need to call the base class constructor with some parameters (not hard-coded into the derived class) and then also the derived class constructor with more parameters? For example, making an instance of Drink with the name "hot chocolate" and a volume of 7 ounces? Would it look something like Drink( string name, double ounces ) : MenuItem( name ) ? Or is it something different?
Hi, thanks it was a plain and good explanation, yet I have this question, is it possible to instantiate the derived and base class param constructor in run time, for example at the end you instantiated the base class at run time by giving it a string is there any notation which I could give the string and the ounces at the same time?
One question: What if my base class has only a constructor with parameters, and my derived class has only a seperate constructor with parameters? Is there a way to put in parameters for both constructors at the same time?
Like when you create the object, you want to provide arguments for both constructors, one in the base class and one in the derived class? The only way to do that, that I'm aware of, is to make a derived class constructor that accepts whatever parameters are needed for itself and whatever the base class constructor would need. And then that construct can "do some work" and then call the base class constructor as well. So you still only use one constructor when making the object, but the derived class constructor uses the base class constructor to have it do work too.
So in general that is not something we want to do, the idea is that the parent class constructor sets up any member variables that the child class uses too. It may be possible though, there is an answer here for example: stackoverflow.com/questions/4065109/not-calling-base-class-constructor-from-derived-class
Hello, thank you for this video, however I have faced a problem working on a project, what if the based param constructor was protected and not public, how can we use it from the derived constructor ?
Can you maybe share your code in a comment so I can see what you're trying to do? :-) In general we cannot make something "more public" in a derived class... if it's protected in the base class it should be protected in the derived class too. So I'm just wondering what your code looks like and what you mean by "use it".
@@PortfolioCourses Thank you for your reply, here is the part of the code : ----- header file ---- class Piece : public CObject { private: CString model; // type of the piece protected: CString reference; // reference of the piece Piece(CString); // constructor, the parameter gives the piece type ; the reference will be composed of the three first letters of the type, all defined in cpp file below. public: Piece(); // default constructor, the type of the piece will be "piece" and the reference to "NR" in cpp file. void display(); //function that will display the model and reference }; class Engine : public Piece { private: int cptref; // counter public: Engine(); // default constructor, the type of the piece will be "engine" and the reference will be composed of the 3 first letters of the type followed by a underdash "_" then the number of the piece. void display(); }; ------- cpp file ------- Piece::Piece() { model = _T("piece"); reference = _T("NR"); } Piece::Piece(CString type) { modele = type; reference=modele.Left(3); } void Piece::display() { cout
dude you are a legend I have been stuck with that error with the parametrized constructor and no default one but actually, the using base_class::base_class Methode didn't work with me I don't know why
I'm really glad to hear this video helped you out Mowafk! :-) I'm not sure why that wouldn't work for you, if you post your code here in a comment I could take a look at it (or maybe someone else may be able to help you out too if I can't).
Easily the most concise explanation on this topic on YT. You answered every single one of my questions. Thanks a lot and I hope you get more recognition for your awesome work!
You’re very welcome, I’m happy to hear the video answered your questions! :-)
Insanely underrated video lectures you are giving out for free, I am going to college soon and this has been a great help, will share with my friends(if i make any)👍
I'm really glad to hear you're enjoying the video lectures, and thank you so much for sharing them with people, that's very much appreciated! :-D
This was exactly what I was looking for, thank you so much!
Very good explanation. Addressed all the nuances that I was struggling with. Thanks!
I'm so glad to hear that Shovnik, and you're welcome! :-)
Great explanation! I hope your channel grows!
Thank you very much for the encouragement! :-)
Clear explanation, well done
Thank you very much Sergio! 🙂
Okay that's cool, but what if I need to call the base class constructor with some parameters (not hard-coded into the derived class) and then also the derived class constructor with more parameters? For example, making an instance of Drink with the name "hot chocolate" and a volume of 7 ounces?
Would it look something like Drink( string name, double ounces ) : MenuItem( name ) ? Or is it something different?
That should work yes. :-)
@@PortfolioCourses Thank you very much! :D
You’re welcome! :-)
very good explanation, thanks!
Hi, thanks it was a plain and good explanation, yet I have this question, is it possible to instantiate the derived and base class param constructor in run time, for example at the end you instantiated the base class at run time by giving it a string is there any notation which I could give the string and the ounces at the same time?
Thankyou so munch man
You made it clear
You're welcome David, I'm glad that it made things clear! :-)
Which is the IDE that you are using?
One question: What if my base class has only a constructor with parameters, and my derived class has only a seperate constructor with parameters? Is there a way to put in parameters for both constructors at the same time?
Like when you create the object, you want to provide arguments for both constructors, one in the base class and one in the derived class? The only way to do that, that I'm aware of, is to make a derived class constructor that accepts whatever parameters are needed for itself and whatever the base class constructor would need. And then that construct can "do some work" and then call the base class constructor as well. So you still only use one constructor when making the object, but the derived class constructor uses the base class constructor to have it do work too.
@@PortfolioCourses Thanks!
@@gavinthecrafter You're welcome! 🙂
hello sir great video , how can we stop the parent class constructor to be used in the child class ? thanks
So in general that is not something we want to do, the idea is that the parent class constructor sets up any member variables that the child class uses too. It may be possible though, there is an answer here for example: stackoverflow.com/questions/4065109/not-calling-base-class-constructor-from-derived-class
Hello, thank you for this video, however I have faced a problem working on a project, what if the based param constructor was protected and not public, how can we use it from the derived constructor ?
Can you maybe share your code in a comment so I can see what you're trying to do? :-) In general we cannot make something "more public" in a derived class... if it's protected in the base class it should be protected in the derived class too. So I'm just wondering what your code looks like and what you mean by "use it".
@@PortfolioCourses Thank you for your reply, here is the part of the code :
----- header file ----
class Piece : public CObject
{
private:
CString model; // type of the piece
protected:
CString reference; // reference of the piece
Piece(CString); // constructor, the parameter gives the piece type ; the reference will be composed of the three first letters of the type, all defined in cpp file below.
public:
Piece(); // default constructor, the type of the piece will be "piece" and the reference to "NR" in cpp file.
void display(); //function that will display the model and reference
};
class Engine : public Piece
{
private:
int cptref; // counter
public:
Engine(); // default constructor, the type of the piece will be "engine" and the reference will be composed of the 3 first letters of the type followed by a underdash "_" then the number of the piece.
void display();
};
------- cpp file -------
Piece::Piece()
{
model = _T("piece");
reference = _T("NR");
}
Piece::Piece(CString type)
{
modele = type;
reference=modele.Left(3);
}
void Piece::display()
{
cout
dude you are a legend I have been stuck with that error with the parametrized constructor and no default one
but actually, the using base_class::base_class Methode didn't work with me I don't know why
I'm really glad to hear this video helped you out Mowafk! :-) I'm not sure why that wouldn't work for you, if you post your code here in a comment I could take a look at it (or maybe someone else may be able to help you out too if I can't).
Thanks man!!!
You’re welcome! :-)
thank you very much
You're welcome Arafath! :-)
thank you!
You're welcome! :-)