首页 > 解决方案 > cpp:如何定义从指向类的指针动态分配的字段?

问题描述

我如何在c ++中从指向类的指针动态分配字段?

这是我的课车

class Veh{
protected:
    double weight;
    int width,height;
public:
    Vozilo(double weight=0, int width=0,int height=0)
    {
        this->weight=weight;
        this->width=width;
        this->height=height;
    }
    ~Veh(){}
};

在这个类中,我想从指向 Veh 类的指针中分配字段

class Parking
{
private:
    Vozilo *ptr;
    int len;
public:
    Parking(Vozilo *ptr, int len)
    {
        this-> *ptr = new *Vozilo[len];
    }
};

我不知道该怎么做。

标签: c++pointersdynamicallocation

解决方案


推荐阅读