应该在UML图中表示朋友函数吗?

dar*_*rko 5 c++ uml

另外,如何在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 &);
};
Run Code Online (Sandbox Code Playgroud)

这是我到目前为止的UML图:

在此输入图像描述

Alo*_*ave 3

通过将构造型放置<<friend>>在 UML 类图中的操作前面。你必须这样做:

<<friend>> ostream& operator << (ostream&, const matrix&)
<<friend>> bool operator == (const matrix &, const matrix &)
<<friend>> matrix operator - (const matrix &, const matrix &)
Run Code Online (Sandbox Code Playgroud)

  • 刻板印象朋友的例子是什么?意大利面食爱好者?:) (3认同)