How memory is allocated in the classroom?

Let's say we have a class
class Examp{
 int size;
 string str2;
 string *str3;
 vector<int> arr1;
 vector<int> *arr2;
 arr2 = new vector<int>();
 str3 = new string();
 delete arr2;
 delete str3;

int main(){
 Examp ex = new Examp ();
 delete ex;
 Examp ex2();

Where memory is allocated for variables in the case of dynamic and static ads?
June 10th 19 at 15:22
2 answers
June 10th 19 at 15:24
Examp ex = new Examp ();
Invalid code must Examp* ex = new Examp;

In the case of static definitions (Examp ex2;) — in the memory where objects are usually located. That is:
• If this field object in the body of the object, which could be anywhere (heap, data segment, stack).
• If static/global in the data segment.
• If the local — on the stack. Specifically, there is a local variable, and it will be on the stack.

In the case of dynamic definition (Examp* ex = new Examp;) in the heap.
In this example, except for the operation new, which starts the object on the heap, and we see another pointer that you'll "usually" in the body of the object, the data segment or the stack.
June 10th 19 at 15:26
The answer to this is in the standard language.
For starters, we have a specification of the location.
Secondly, we have a specification of the fields of the class.
10-th item specifications class fields suggests that the fields of invalid class specifiers extern and thread_local, and therefore only valid static and mutable.
Specifier mutable does not affect the actual location of the fields in the class.

Hence is inferred that the location of the fields affects only class specifier static, which takes the field in the area of permanent placement.

Otherwise, the location of all non-static class fields produced within the memory of the object being created.

Find more questions by tags C++Programming