С++ массив базового класса

Не так давно начал изучать С++, перешел с паскаля и я правильно понял, что как такого массива базового класса в С++ нет? а как быть тогда? гуглил и нашел такой способ mas[0] = new GraphicFile(...); если объявлять сам массив в мейне и добавлять таким способом там же, то вроде все работает но как сделать так, как я хочу? а точнее это по заданию... заранее спасибо за ответы

using namespace std;
//--------------------------------------------------------------------------------------------------

class Files
{
private:
string name;
public:
Files()
{
    name = "";
}
Files(string a_name)
{
    name = a_name;
}

string  GetName()
{
    return name;
}

void SetName(string new_name)
{
    name = new_name;
}


string  virtual Show() = 0;

string GetDate()
{

    //return  name + Show();
}
};

class GraphicFile : public Files
{
private:
int  NamberOfPixel;
public:

GraphicFile(string a_name, int a_NamberOfPixel) :Files(a_name)

{
    NamberOfPixel = a_NamberOfPixel;
}
int  GetNamberOfPixel()
{
    return NamberOfPixel;
}

void  SetNamberOfPixel(int New_NamberOfPixel)
{
    NamberOfPixel = New_NamberOfPixel;
}
string Show() override
{
    return to_string(NamberOfPixel);
}
};


class AudioFile : public Files
{
private:
float TimeOfAudio;
public:
AudioFile(string a_name, float a_TimeOfAudio) : Files(a_name)
{
    TimeOfAudio = a_TimeOfAudio;
}
float  GetTimeOfAudio()
{
    return TimeOfAudio;
}
void SetTimeOfAudio(float new_TimeOfAudio)
{
    TimeOfAudio = new_TimeOfAudio;
}

string Show() override
{
    return to_string(TimeOfAudio);
}

};



class FileContainer
{
private:
int  size;
int count = 0, count2;


Files* mas[10];
public:


FileContainer(const int size)
{
    this->size = size;
}
int  GetCount()
{
    return count;

}
void AddFile(Files &file)
{
    if (count>size)
    {
        cout << "error!" << endl; 
        //break;
    }
    else
    {
        *mas[count] = file;
        count++;
    }
}

void DeleteFile(int nom)
{
    //&mas[nom] = nil;
    count--;
}

void  GetAllDate()
{
    for (int i = 0; i < size; i++)
    {
        cout << mas[i]->GetName() << endl;
    }
}
};


int main()
{
string name;
float time;
int amount;
int menu;
FileContainer container(10);
Files *p;


do {
    ignorecin; //игнорирование символов 
    cout << "1-A" << endl;
    cout << "2-audio" << endl;
    cin >> menu;
    switch (menu)
    {

    case 1:
    {
        cout << "enter name for the audiofile" << endl;
        cin >> name;
        cout << "enter " << endl;
        cin >> amount;
        GraphicFile graphicfile(name,amount);
        container.AddFile(graphicfile);
       // container.GetAllDate();
        break;
    }

    case 2:
    {
        cout << "enter name for the audiofile" << endl;
        cin >> name;
        cout << "enter " << endl;
        cin >> time;
        //AudioFile  audiofile(name, time);
        //audiofile.Show();
        break;
    }
    }
} while (menu != 6);

}

Ответы (0 шт):