c++ - 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];
}
};
我不知道该怎么做。
解决方案
推荐阅读
- sql - SQL - 计算多个组
- spring-boot - 应用程序属性与静态变量
- python - 蟒蛇硒:元素不可交互
- amazon-web-services - AWS lambda函数上传文件
- javascript - innerHTM 或 innerText 写入屏幕但在 console.log 中提供正确信息
- c# - 如何打印 C# 控制台写行?
- google-custom-search - 如何将页面地图与谷歌自定义搜索优化一起使用?
- javascript - 使用 ESPIRMA 生成 JS AST 时忽略错误
- react-native - onPress{} 内的差异调用函数
- android - 如何正确填充 RecyclerView?