首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

cpp静态成员跟普通成员

2012-09-09 
cpp静态成员和普通成员// object_static_002.cpp : Defines the entry point for the console application

cpp静态成员和普通成员

// object_static_002.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>using namespace std;class C1 {public:C1() { cout << "c1构造" << endl; }C1( char* name ) { cout << name << "构造" << endl;}~C1() { cout << "C1析构" << endl;}void  fuck() { cout << "Fuck you" << endl; }};class C2 {C1 member;static C1 static_member;public:C2() { cout << "C2构造" ;  member.fuck(); }~C2() { cout << "C2析构" << endl;}};//C1 C2::static_member = C1( "static_member" );C1 C2::static_member( "static_member" );void test(){C2 c;}int main(int argc, char* argv[]){test();return 0;}


执行结果

/*********************************static_member构造c1构造C2构造Fuck youC2析构C1析构*********************************/

热点排行