类和向量

我在下面有此类,我想将HomePC保存到向量中,我可以采用的方法是什么,以及如何从向量中打印第一个或第二个元素。


class PC
{
public:
    PC(string in_operatingSystem,int in_ramSlots,int in_pcieSlots,int in_totalRamSlots, int in_gbPerRam, int in_cpu, int in_ssd, int in_cost);

    virtual void Print() = 0;
    virtual void Upgrade() = 0;
protected:
    string operatingSystem;
    int ramSlots,pcieSlots,totalRamSlots,gbPerRam;
    int cpu,ssd;
    int cost;
};

class HomePC: public PC
{
public:
    HomePC(string in_operatingSystem,int in_ramSlots,int in_pcieSlots,int in_totalRamSlots, int in_gbPerRam, int in_cpu, int in_ssd, int in_cost, string in_model);

    void Print();
    void Upgrade();
private:
    string model;
};
评论