C++ 结构体

#include <iostream>

struct student {
        int a;
        int b;
        int add(){  //在结构体内封装了函数 
            return a+b;
        }
    };

int main(){
    
    student s={10,20}; 
  //c++时
struct 可以省略
int x=s.add(); printf("%d\n",x); }

 

C++ 结构体

相关文章: