对象数组的构造方法
来源:互联网 发布:淘宝精仿鞋店推荐 编辑:程序博客网 时间:2024/05/22 07:40
#include <iostream>
using namespace std;
class Person
{
string name;
int id;
public:
Person(string name,int id)
{
this->name = name;
this->id = id;
}
void display()
{
cout<<"name :"<<this->name<<","<<"id :"<<this->id<<endl;
}
};
int main()
{
Person *p[10];
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
p[i] = new Person("狗博", i);
}
for(int i=1;i<=n;i++)
{
p[i]->display();
}
return 0;
}
using namespace std;
class Person
{
string name;
int id;
public:
Person(string name,int id)
{
this->name = name;
this->id = id;
}
void display()
{
cout<<"name :"<<this->name<<","<<"id :"<<this->id<<endl;
}
};
int main()
{
Person *p[10];
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
p[i] = new Person("狗博", i);
}
for(int i=1;i<=n;i++)
{
p[i]->display();
}
return 0;
}
阅读全文
0 0
- 对象数组的构造方法
- C++对象数组调用构造/析构函数的方法
- 继承与构造方法与对象数组
- Event()对象的构造方法
- 面向对象的构造方法:
- Java面向对象02-方法的签名,重载,构造方法和引用类型数组
- 带参构造函数为结构体对象数组赋值的方法
- 带参构造函数为结构体对象数组赋值的方法
- 9/7 javasScript对象、构造函数、数组的迭代方法
- 构造对象数组
- Java的file对象的构造方法
- window.showModalDialog方法返回值为对象,若Dialog窗口中返回的对象为数组,会丢失数组构造信息,不能对返回值使用Array方法。
- php构造json多维数组的方法
- new对象数组是否会调用对象的构造函数
- 面向对象的编程,构造方法
- 关于构造方法与对象的创建
- java的构造方法和匿名对象
- C++ 回忆录5 对象的构造方法
- Contest5.StringReverse
- 20171113 自省
- 阿里云ECS CentOS7.2 搭建Shadowscoks
- Linux权限管理之ACL权限最全解读
- 网站知识基础+网站搭建方法
- 对象数组的构造方法
- 在 Python 中实现单例模式
- vue 打包优化
- 2017年做高薪Linux运维最后的机会来了
- “安装程序无法创建新的系统分区,也无法定位现有分区”
- HDU 2844 Coins(二进制优化)
- laravel 开发RestFul接口【二、集成三方扩展
- 理解异步IO模型
- Redis的持久化方案