Home > Back-end >  Could you tell me how to write this topic
Could you tell me how to write this topic

Time:12-12

1 declare a class People to
At least id 0 (string), age (int), and other members of the variables;
(2) implement constructor;
3. Love is the destructor:
(4) at least output id, add a member function such as the age;
(5) using the new operator to generate at least one object;
6. Use the delete operator to delete at least one object;

CodePudding user response:

There are big? Help me

CodePudding user response:

This is a c + + class,,,,
 class People 
{
Public:
People (string id, int the age);
~ People ();
Private:
String id;
int age;
};

People: People (string id, int age)
{
This - & gt; Id=id;
This - & gt; Age=age;
}

People: : ~ People ()
{
Id. The clear ();
}

 People * p1=new People (" 0001 ", 20). 
The delete p1;

Slipped to slip
  • Related