第一默认的访问权限不同
class默认的成员访问权限是private
struct默认的从成员访问权限是public
#include <iostream>
using namespace std;
class structAndclass
{
int x;
};
struct structs
{
int x;
} int main(int argc, char const *argv[])
{
structs s;
s.x = 20;
structAndclass ss;
ss.x = 21;
return 0;
}
第二点
struct 默认的继承方式是public
class默认的继承方式是private
#include <iostream>
using namespace std;
class structAndclass
{
public:
int x;
};
struct structs
{
public:
int x;
} class sonclass : structAndclass
{
int y;
} class sonstruct : structs
{
int y;
}
int
main(int argc, char const *argv[])
{
sonstruct s;
s.y = 10;
sonclass ss;
ss.y = 13;
return 0;
}
第三点
class可以用于定义模板参数
struct不能