#include <iostream>
using namespace std;
class class1 { public:
class1(){ }
class1(int i ){ }
void show(){ cout<<"this is output by class1 ! \n ";
}
};
int main(){
// static allocation :
/* class1 oneclass(); oneclass.show(); error : request show() function of non-class oneclass . because : compile thinks of oneclass1 oneclass() as of function declaration with name 'oneclass' and the return type class1 */
/*
class1 secondclass(1); secondclass.show();
*/
//dynamic allocation : class1 * thirdclass = new class1(); thirdclass->show(); return 0;
}

 

 总结一下:

1. 当使用类的无参构造函数来实例化对象时,有两种方法:

   类名  * x = new 类名();

  类名  x;

2 . 当使用有参的构造函数时,有两种方法:

  类名 * x = new 类名(参数列表);

  类名 x(参数列表);

注 :编译器版本 : 

最新文章

  1. css多行文本省略号问题
  2. 国内SEO如何过滤掉不良网络信息
  3. xcode armv6 armv7 armv7s arm64
  4. 能源项目xml文件标签释义--CommonsMultipartResolver
  5. 计算机原理学习(2)-- 存储器和I/O设备和总线
  6. Baskets of Gold Coins
  7. [COGS 2524]__完全平方数
  8. npm下载包很慢和node-sass编译错误的解决办法
  9. Apache启动不了httpd: apr_sockaddr_info_get() failed xgp
  10. Conway生命游戏
  11. Vim 安装 YouCompleteMe
  12. Exception in thread &quot;main&quot; java.lang.UnsatisfiedLinkError: org.apache.hadoop.io.nativeio.NativeIO$Windows.access0(Ljava/lang/String;I)Z
  13. python实例[判断操作系统类型]
  14. Eclipse CDT 插件列表
  15. [Docker] Building a Node.js Image
  16. mac pro 显示隐藏文件
  17. qt基本类
  18. zookeeper的安装及共享锁的应用
  19. [原][译][osgearth]Model Source Drivers模型驱动源(OE官方文档翻译)
  20. PHP——文件操作

热门文章

  1. 常用chrome插件推荐
  2. Java常用命令
  3. PHP学习之常量
  4. Angular JS 学习之服务(Service)
  5. Windows64 系统下Python、NumPy与matplotlib 安装方法
  6. 分享Kali Linux 2016.2第43周镜像
  7. [R]R的工作流
  8. 串 &amp; 容斥原理
  9. UIColletionView 的属性与常用方法介绍
  10. HDU-统计难题