C++之4种实例化对象方式(一百一三十一)
2023-09-14 09:09:57 时间
1.程序例子
#include <iostream>
using namespace std;
class Student{
public:
Student(){
printf("%s(), line = %d\n",__FUNCTION__,__LINE__);
}
Student(int cc){
this->data = cc;
printf("%s(), line = %d, data = %d\n",__FUNCTION__,__LINE__,this->data);
}
int data;
};
int main(){
//1.隐式创建(栈上创建)
Student st1;
//2.显示创建(栈上创建)
Student st2 = Student();
//3.new堆上创建
Student *st3 = new Student;
//4.new实例化后直接赋值给st4对象
Student *st4(new Student());
//Student *st5(new Student(44));
return 0;
}
相关文章
- c++语言截取字符串,详解C++ string常用截取字符串方法
- C++ Socket编程实例解析[通俗易懂]
- c++ auto类型_auto C++
- C++基本概念_c语言 c++区别
- C/C++ 实现正向CMDShell
- C++ 线程操作
- 开心档之C++ 多线程
- C++默认参数(函数参数的默认值)
- C++ map的创建(STL map的创建)详解
- C++ search(STL search)算法详解
- C++类对象的创建和使用(详解版)
- Java和C/C++到底有什么关系?它们有什么区别?
- C和MySQL的结合应用实例研究(c++ mysql 实例)
- c++读写文件流实例程序讲解
- C与C++之间相互调用实例方法讲解
- C++中Semaphore内核对象用法实例
- C++采用TLS线程局部存储的用法实例
- C++基于对话框的程序的框架实例
- C++读取INI配置文件类实例详解
- C++实现判断字符串是否回文实例解析
- C++智能指针实例详解
- C++实现简单的希尔排序ShellSort实例
- C++实现inlinehook的原理及应用实例
- CISBitmap派生的VC++位图透明类实例
- C++继承中的访问控制实例分析
- C++多重继承和虚拟继承对象模型、效率分析
- C++命名空间实例解析
- C++编译器无法捕捉到的8种错误实例分析