想知道C++ CLASS类声明和C 结构体有什么本质区别~ 结构里都是public类型,而class还有private等 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 In C++, a structure is the same as a class except that its members are public by default.Look at this:struct _MyStru:CObject // Declare _MyStru structure{ int x; // Define members x and y int y;} spot = { 20, 40 }; This is OK. 他们的区别是:1 CALSS类中对数据进行了封装,其他对象要直接访问其私有数据是不行的,而STRUCT中的数据就可以直接访问。2 CLASS有继承的概念,而STRUCT没有3 CLASS中的成员函数有虚拟、重载、动态束定等概念,而STRUCT中没有。4 ...... 总之,他们的区别基本上就是OOP和结构化程序设计的区别。建议你去看看有关OOP的书。 struct 中的成员缺省是 public 的,而class 中的成员缺省是 private 的struct 不支持构造/析构,不支持继承... 在C++中struct 一样可以继承也支持构造/析构 要说的,阿凯都说了,我想,再要强调的是,安全问题,CLASS可以更好地封装和隐蔽数据。 在c\c++里好象struct一样可以继承也支持构造/析构的~~记不清楚啦... 在c++中,struct 和 class根本就是一回事,唯一的区别在于:struct 中的成员缺省是 public 的,而class 中的成员缺省是 private 的,可以这么说:class 是从 struct 发展而来的。之所以将struct和class都保留,是因为:1、提出class是为了强调一种概念。2、保留struct是为了照顾到大多数人的习惯。 jerrycao(jerry)说得非常精确, 举点例子大家才明白吧:typedef struct _SS1 { int mBar;} SS1, *PSS1;typedef class _CS1 {public: int mBar;} CS1, *PCS1;class CObject {public: int mRookies;};struct SFoo : protected CObject {private: int mBar;public: void Fire();};看来大家的C++都急需补课 :) jerrycao很对c++的struct很强,可不比c了,只是struct 中的成员缺省是 public 的class 中的成员缺省是 private 的只要你愿意,不用class...没人会这么做吧:) jerry is right,but I think many of us should improve our lessons 区别在于CLASS的缺省声明为private,Struct缺省声明为public 有什么方法,可以用vc++,实现截图? 编译的问题 小问题:Edit控件 获取Date型数据怎么做?在线等! 简单的MFC 问题 拷屏时不想要菜单怎么做? Unhandled exception…… 98下使用createfile的问题 关于回调函数 VC中有关DLL调用的问题 为什么GetMenuInfo()和MENUINFO无法使用? 需要异形窗口范例!(API) 请教:recordset
struct _MyStru:CObject // Declare _MyStru structure
{
int x; // Define members x and y
int y;
} spot = { 20, 40 }; This is OK.
1 CALSS类中对数据进行了封装,其他对象要直接访问其私有数据是不行的,而STRUCT中的数据就可以直接访问。
2 CLASS有继承的概念,而STRUCT没有
3 CLASS中的成员函数有虚拟、重载、动态束定等概念,而STRUCT中没有。
4 ......
总之,他们的区别基本上就是OOP和结构化程序设计的区别。建议你去看看有关OOP的书。
class 中的成员缺省是 private 的struct 不支持构造/析构,不支持继承...
记不清楚啦...
1、提出class是为了强调一种概念。
2、保留struct是为了照顾到大多数人的习惯。
int mBar;
} SS1, *PSS1;typedef class _CS1 {
public:
int mBar;
} CS1, *PCS1;class CObject {
public:
int mRookies;
};struct SFoo : protected CObject {
private:
int mBar;
public:
void Fire();
};看来大家的C++都急需补课 :)
c++的struct很强,可不比c了,
只是
struct 中的成员缺省是 public 的
class 中的成员缺省是 private 的
只要你愿意,不用class...没人会这么做吧:)