C的结构(struct)和C++中的结构有什么分别?

来源:百度知道 编辑:UC知道 时间:2024/05/12 07:30:57
C的结构(struct)和C++中的结构有什么分别?C++中的结构又和类有什么区别?

c中的struct是没有权限设置的.
C++中的struct等同与class只是class默认成员权限是private而struct默认成员权限是public.

C++中的结构把C中的结构大大扩展了。
我用英语写行吗?用中文写这个太痛苦了。

In C, struct is just a set of vars. In C++, class was involed and infact struct was unnecessary. Structs in C can be easily changed into classes. What's more, class in C++ is much more powerful than struct in C.
In order that C programs can act just well as a C++ program, C++ choosed to keep a struct.

Struct and class are simply the same except that
functions in a class was default set to be private, and that in a struct was default set to be public. Yes, you can declear functions in a struct in C++. Just like the one below:

/*
* an example C++ struct
* passed on WinXPsp2, g++.exe (GCC) 3.4.2 (mingw-special)
*/
#include <iostream>
using namespace std;
struct window
{
bool opening;
void showStatus();
void set(bool status);
};
<