samedi 25 avril 2015

What is the right way to overload the plus operator?

I have set of classes:

class A 
{
public:
    A(B b) {//..}   
    A(C C) {//..}
    A(D D) {//..}

    A& operator+=(A const& ls) {//..}
    A operator+(A const& ls) const {//..}
}

class B
{
//....
}

class C
{
//....
}

class D
{
//....
}

I want to support the following operations:

1) A result = a1 + a2;
2) a1 += a2;
3) A result = b1 + a1; (and C, D classes instead of B)
4) A result = a1 + b1; (and C, D classes instead of B)
5) a1 += b1; (and C, D classes instead of B)

How to do in this case? I would not want to use boost.

Aucun commentaire:

Enregistrer un commentaire