// 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 << "Test" << 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构造Test
C2析构 C1析构 *********************************/