ITeye博客

cpp静态成员和普通成员

qwop · 2012-06-03 16:07 · cpp · 编程语言 · Markdown

[code="cpp"]// object_static_002.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include 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; } [/code] [b]执行结果[/b] [code="cpp"] /********************************* static_member构造 c1构造 C2构造Fuck you C2析构 C1析构 *********************************/[/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。