指针还是变量?

coq*_*qer -1 c++ struct pointers base-class

最近,我正在学习MFC,下面的代码让我很困惑:

  class CRect : public tagRECT
{
public:

// Constructors

// uninitialized rectangle
CRect();
// from left, top, right, and bottom
CRect(int l, int t, int r, int b);
// copy constructor
CRect(const RECT& srcRect);
// from a pointer to another rect
CRect(LPCRECT lpSrcRect);
// from a point and size
CRect(POINT point, SIZE size);
// from two points
CRect(POINT topLeft, POINT bottomR
...
Run Code Online (Sandbox Code Playgroud)

CRect的基类是一个结构!我以前从没学过这个.如果我打电话的话

CWnd :: GetClientRect(LPRECT lpRect);

我可以使用rect&rect(CRect rect)作为参数.这太神奇了!

我想知道有关struct base的类的一些规则.谢谢!

Saq*_*ain 5

在C++中,类和结构是相同的,除了它们关于成员的继承和访问级别的默认行为.

C++类默认继承=私有成员变量和函数的默认访问级别=私有

C++ struct默认继承= public成员变量和函数的默认访问级别= public

简而言之,是的,类可以从C++继承struct.