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

5
此外,在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图表: enter image description here

只是一个建议,用StavrUML/StarUML而不是使用文字处理软件来制作您的UML图表,这样会更容易 :) http://sourceforge.net/projects/stavruml/ - Chris Dennett
1个回答

3
通过在UML类图中的操作前放置构造型<>,您需要按照以下方式进行:
<<friend>> ostream& operator << (ostream&, const matrix&)
<<friend>> bool operator == (const matrix &, const matrix &)
<<friend>> matrix operator - (const matrix &, const matrix &)

3
一个典型的陈词滥调朋友的例子是什么?比如一个热爱意大利面食的意大利人朋友? :) - fredoverflow
@FredOverflow:没关系,可能是我没有好的幽默感 :) - Alok Save

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接