C++中的结构体函数

代码


#include 
" stdafx.h "

struct  Test
{
    
int  num;

    Test() {

        printf(
" 11111111 " );
        
    }
    Test(
int  i)
    {
        
this -> num = i;
    }
    
void  fun() {
        printf(
" fun " );
    }
};
void  main(  void  )
{
    
    Test a(
1 );
    printf(
" %d " ,a.num);
    a.fun();
    Test b();
// 定义了一个函数b,返回值是Test类型
    
// b.fun(); // 错误

}


 

你可能感兴趣的:(C++)