Answer the question
In order to leave comments, you need to log in
The syntax of the new operator?
I have been learning C++ for about 1.5 months.
Recently I saw in a video of a person how, when using dynamic memory, he uses something like this:
A *ptr = new B;
A and B are classes.
Before that, I used dynamic memory when the data types were the same, but here in the example they are different. And I don't understand how they differ. I know that the data type that appears before the name of the variable is the data type of the variable itself, but what does the data type that is written after the new operator mean?
Answer the question
In order to leave comments, you need to log in
what does the data type that is written after the new operator mean?
but here they are different
In general, the data type that is written after the operator new
can mean any fundamental data type or user-defined object.
In this case , this is the type of the class, which is apparently inherited from the class
A* ptr = new B
B
A
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question