static 在C++中的不完全测试

王朝c/c++·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

// file testStatic.cpp

//

#include <iostream>

using namespace std ;

class testStatic

{

public:

static void pnt()

{

cout << "Test: " << endl ;

}

void pnt(int i)

{

cout << "void pnt(int i): " << i << endl ;

}

// overloading function

void pnt(int i) const

{

cout << "void pnt(int i) const: " << i << endl ;

}

// for convienence ,data members are delcared in public field

static const int ival ;

void (testStatic::*pmf)(int) ;

void (testStatic::*pmfc)(int) const ;

} ;

//delcaration is necessary

const int testStatic::ival = 9 ;

//delcaration is necessary

const int *pval = &testStatic::ival ;

//notice the type of static member function pnt

void (* pf)() = &testStatic::pnt ;

// notice the type of member function pnt

void (testStatic::*pmf)(int) = &testStatic::pnt ;

// notice the type of const member funtion pnt

void (testStatic::*pmfc)(int) const = &testStatic::pnt ;

int main(char argc ,char *argv[])

{

testStatic ts ;

ts.pnt() ;

cout << "using class member pointer: " << *pval << endl ;

cout << testStatic::ival << endl ;

(ts.*pmf)(2) ;

(ts.*pmfc)(2) ;

ts.pmf = &testStatic::pnt ; //assign value again

(ts.*pmf)(3) ;

return 0 ;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航