class Base{ 
   char* s1;
   public: ...
             ~Base(){
                 delete s1}
   }
class Derived:public Base{
   char* s2;
   public: ...
              //the constructor of the derived class will call the constructor of the
              //base class, so derived will contain s2 and s1 too.    
              ~Derived(){
                //HERE
               }

void main(){
...
Base x[5];
...
};

Questions:

1. what should i write in the destructor of the derived class?
does the derived class inherites the destructor from the
base class, so that in the destructor of the derived class the
destructor of the base class will be called automatically, and
i only have to delete s2? or it doesnt and i have to delete there
both elements (and if so, does the order matters)?

2. is the statement "Base x[5];" correct? can i store in a vector
elements of type class? or i can only reffer to the class by a
pointer?

1) This looks like a perfect place to run a simple test on your own:

#include <iostream>

class Base {
public:
  ~Base() { std::cout<<"Base\n"; }
};

class Derived: public Base {
public:
  ~Derived() { std::cout<<"Derived\n"; }
};

int main()
{
  Derived d;
}

2) Sure, if you want an array of Base objects. If you want to be able to store both Base and Derived instances you probably want to use pointers to enable polymorphism. And if you're going to be using Derived polymorphically, I would recommend making your destructors virtual to avoid slicing.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.