dimanche 9 mai 2021

Operator overload different operand types

I'm trying to reinterpret an operator for a class (C), and that will require me to take different operand type inputs (with my very very sparse knowledge). How would be a good approach to achieve this. If it is even achievable. The below example is an example of what I want to achieve, and does not compile.

Including class C in the overloading of >> will compile and work, but doesn't exactly achieve what i want.

class A {


};

class B {
    A a;
    A b;

};


class C{
    
public:

    C() {}

    friend B operator >> (const A& a, const A& b) {
         //.. combine these into B by added a and b into b
         B b;
         b.a = a;
         b.b = b;

Aucun commentaire:

Enregistrer un commentaire