【问题标题】:What the function's signature means?函数的签名是什么意思?
【发布时间】:2020-04-04 20:04:32
【问题描述】:
#ifndef _RECT
#define _RECT

#include "Point.h"

using namespace std;

class Rectangle
{
private: 
    Point _topLeft;
    Point _bottomRight;
    int _color;

public:
    Rectangle( double left, double top, double width, double height, int color );
    ~Rectangle() { --m_count; };

public:
    int getColor() const;
    Point& getTopLeftPoint();

    Point& getBottomRightPoint();
    void setColor( int color );

public:
    bool contains( const Point &p );
    void moveRect( double deltaLeft, double deltaTop );
    void scaleRect( double rectWidth, double rectHeight );


    void setBigger(int x, int y) const;

public:
    static int m_count;
};

#endif

我没看懂签名的意思:

Point& getTopLeftPoint();
Point& getBottomRightPoint();

它们属于哪里,是另一个类构造函数还是调用变量的另一种方式, 我已经想了好几个小时了

感谢您的帮助

【问题讨论】:

  • 函数返回对Point的引用
  • 以下划线后跟大写字母的标识符、带有双下划线的标识符以及在全局范围内以下划线开头的标识符是保留的,因此使用它们是未定义的行为。你应该改变_RECT

标签: c++ visual-c++ methods func datamember


【解决方案1】:

这是初级 C++ 语言,所以您可能想复习一下您的知识。

它们是返回对Point 的引用的成员函数(或方法,如果您更喜欢这个术语)。如果将返回类型 Point & 替换为例如 int,则语法应该看起来很熟悉。否则,你真的需要回去学习基础知识。

【讨论】:

  • 感谢指导 我刚开始学习这门语言,一时不明白它的意思
猜你喜欢
  • 2018-02-06
  • 2011-10-05
  • 2016-01-16
  • 2013-01-04
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
  • 2010-10-01
  • 1970-01-01
相关资源
最近更新 更多