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); }

 

posted @ 2020-07-29 21:12  天子骄龙  阅读(144)  评论(0编辑  收藏  举报