-
什么是封装?
将函数定义到结构体内部,就是封装。
-
什么是类?
带有函数的结构体,称为类。
-
什么是成员函数?
结构体里面的函数,称为结构函数。
结构体中定义的函数并不占用空间。
#include <iostream>
struct MyStruct
{
int a;
int b;
int c;
int add()
{
return a + b + c;
}
};
int main()
{
MyStruct test = { 1,2,3 };
std::cout << test.add();
return 0;
}