You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
parameter names are not important... different names make sense so that something is not confused with something...
You can write some values in the function declaration,
and other values in the function itself
or you can name the parameters identically everywhere, whichever is more convenient for the code-writer
In the same textbook, the code came across:
Strange thing about the constructor:
Why is there a return operator here?This is the first time I've seen this operator used in the constructor. In fact, the constructor is called automatically. And there will be an output anyway. Does this operator make sense in the constructor?
In the same textbook, the code came across:
Strange thing about the constructor:
Why is there a return operator here?This is the first time I've seen this operator used in the constructor. In fact, the constructor is called automatically. And there will be an output anyway. Does this operator make sense in the constructor?
It is not needed in this example, but there can be complex initialization when early exit is needed.
The constructor and destructor are normal functions. Only the default constructor and destructor are called automatically. The others are called by the user.
The textbook gives this example in relation to polymorphism:
There's one thing I don't understand. If we use child function objects for calls, i.e. derived methods CCircle and CSquare, then GetArea() area can be calculated bypassing declarations in base class. I.e. do not create virtual functions in base class at all, and in derived methods create a simple method and that's it! So why do we need a virtual function?
It's interesting to see an adequate and logical example, where you can see that virtual functions provide some benefit. Because what I saw was not logical, at least for me. I would like to understand it all the same.
The textbook gives this example in relation to polymorphism:
There's one thing I don't understand. If we use child function objects for calls, i.e. derived methods CCircle and CSquare, then GetArea() area can be calculated bypassing declarations in base class. I.e. do not create virtual functions in a base class at all, and in derived methods create a simple method and that's it! So why do we need a virtual function?
It's interesting to see an adequate and logical example, where you can see that virtual functions provide some benefit. Because what I saw was not logical, at least for me. I would like to understand it all the same.
This is the simplest sample for understanding polymorphism. To get it quickly.
There are complicated cases. You will apply it when you need it. There's no sense in bothering now. When the task is done, you'll have to think about it.
For example, I have a base class with all possible read/write interfaces. It also has private virtual methods (2 in total - read/write), which link this interface in the base class with derived classes. Actually the derived classes can be any where there is work with files (files, mapping, channels, internet). Each of the derived classes defines these virtual methods differently, but all classes have the same interface from the base class.
The textbook gives this example in relation to polymorphism:
There's one thing I don't understand. If we use child function objects for calls, i.e. derived methods CCircle and CSquare, then GetArea() area can be calculated bypassing declarations in base class. I.e. do not create virtual functions in base class at all, and in derived methods create a simple method and that's it! So why do we need a virtual function?
It's interesting to see an adequate and logical example, where you can see that virtual functions provide some benefit. Because what I saw was not logical, at least for me. I want to understand it all the same.
I will try to sketch a small sample:
Thanks to this structure, we won't need to get into working algorithm, which can be very big and complex (everything is simplified here), we will only need to add one more descendant, m3 in enumeration and one more case in switch. That is, we have unified the input data, which will avoid editing in the main part of the program.
Of course, this will only be appropriate if the working algorithm accepts a variety of types as input. If there is only one type, all of this is useless.
The textbook gives this example in relation to polymorphism:
There's one thing I don't understand. If we use child function objects for calls, i.e. derived methods CCircle and CSquare, then GetArea() area can be calculated bypassing declarations in base class. I.e. do not create virtual functions in a base class at all, and in derived methods create a simple method and that's it! So why do we need a virtual function?
It's interesting to see an adequate and logical example, where you can see that virtual functions provide some benefit. Because what I saw was not logical, at least for me. I would like to understand it all the same.
Here's a simple example:
We use the GetArea() function without knowing which shape it is called for.I have this setter in a class:
The compiler is generally fighting this assignment of elements to the ColorBySend array like this:
What does this have to do with? Is it really necessary to assign values element by element? Isn't it possible to do it as a list? What is it related to? After all, that's how the assignment works even in the textbook...I have this setter in a class:
The compiler swears at this assignment of elements to the ColorBySend array in general like this:
What does this have to do with? Is it really necessary to assign values element by element? Isn't it possible to do it as a list? What does it have to do with it? After all, this is how assignment is done even in the textbook...is a variable expression which the compiler cannot understand. Alas.