【问题标题】:should friend functions be represented in UML diagrams?友元函数应该在 UML 图中表示吗?
【发布时间】:2011-05-14 15:46:55
【问题描述】:

另外,重载的运算符成员函数在 UML 图中的最佳格式究竟是怎样的?

这是我的课:

class matrix
{
    friend ostream& operator << (ostream&, const matrix&);
    friend bool operator == (const matrix &, const matrix &);
    friend matrix operator - (const matrix &, const matrix &);

    private:
    int size;
    int range;
    int array[10][10];

    public:
    matrix(int);
    matrix(int, int);
    bool operator != (const matrix &) const;
    matrix operator + (const matrix &) const;
    const matrix & operator = (const matrix &);
};

这是我目前的 UML 图:

【问题讨论】:

标签: c++ uml


【解决方案1】:

通过将构造型&lt;&lt;friend&gt;&gt; 放在UML 类图中的操作前面。 你必须这样做:

<<friend>> ostream& operator << (ostream&, const matrix&)
<<friend>> bool operator == (const matrix &, const matrix &)
<<friend>> matrix operator - (const matrix &, const matrix &)

【讨论】:

  • 什么是刻板印象朋友的例子;意大利面食爱好者? :)
  • @FredOverflow: :) 不用担心,我可能没有幽默感 :)
猜你喜欢
  • 1970-01-01
  • 2022-01-21
  • 2016-09-29
  • 2019-04-15
  • 1970-01-01
  • 2016-11-08
  • 1970-01-01
  • 2018-02-12
  • 1970-01-01
相关资源
最近更新 更多