指针或变量

pointer or variable?

本文关键字:变量 指针      更新时间:2023-10-16

最近,我正在学习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
...

CRect的基类是一个结构体!我以前从来没学过这个。如果我调用

CWnd:: GetClientRect (LPRECT LPRECT);

我可以使用rect&rect (CRect rect)作为参数。这是惊人的!

我想知道一些关于struct base类的规则。谢谢你!

在c++中,除了在继承和成员访问级别方面的默认行为外,类和结构是相同的。

c++类默认继承= private成员变量和函数的默认访问级别= private

c++结构默认继承= public成员变量和函数的默认访问级别= public

简而言之,class可以继承c++中的struct。