c++类实例化的两种方式
来源:互联网 发布:c语言 if else用法 编辑:程序博客网 时间:2024/06/04 18:34
从堆中实例化
从栈中实例化
1 //类中有构造函数的情况下
class temp{public: //构造函数 temp(int Num, string abc) { theNum = Num; theabc = abc; } void printf() { cout << theNum << theabc << endl; }private: int theNum; string theabc;};int main(){ //从栈中实例化 temp ywb(10,"yangwenbin"); ywb.printf(); system("pause");}int main(){ //从堆中实例化 temp *p = new temp(10,"yangwenbin"); p->printf(); getchar();}
类中无自定义的构造函数时,编译器会自动生成
class temp{public: int theNum; string theabc; char name[10];};int main(){ //从堆中实例化 temp *p = new temp[10]; temp *q = new temp(); q->theNum = 10; q->theabc = "ywb"; delete []p; delete q; return 0;}int main(){ //从栈中实例化 temp ywb; temp ywb1[10]; ywb.theabc = "yangwenbin"; ywb.theNum = 10; ywb1->theabc = "yanwenbin1";}
0 0
- String类的两种实例化对象的方式
- c++类实例化的两种方式
- C++类的实例化--两种方式
- c++类实例化的两种方式
- 实例化Spring容器常用的两种方式
- String类实例的两种分配方式
- 实例化spring容器两种方式
- 两种Selenium WebDriver实例化方式
- Objective—C中声明实例变量的两种方式
- c#Gdi画图的两种方式
- C获取时间的两种方式
- 类的两种实例化方法
- java线程实现的两种方式实例
- java线程实现的两种方式实例
- C++11: unordered_map实例化时传参的两种方式
- SpingAOP两种配置方式的简单实例
- Java 动态代理的两种方式实例
- java中的引用类型概念和String两种实例化方式的区别
- 使用透明度实现Mask遮罩的Unity Shader
- win10
- Android Framework学习(八)之Handler消息机制(Native层)解析
- 【转载】Opencv同时调用两个摄像头
- Ubuntu 放弃 Unity 界面:公司大裁员
- c++类实例化的两种方式
- leetcode题解-75. Sort Colors && 442. Find All Duplicates in an Array
- 多网卡存在情况下获取指定网卡的MAC地址
- AES加解密算法在Android中的应用及Android4.2以上版本调用问题
- java连接读取access数据库可行方法
- PHP中foreach()用法汇总
- nginx配置SSL启用HTTPS
- 机器学习入门介绍
- Maven中国镜像