lundi 2 octobre 2017

c++ receive const lvalue and rvalue reference parameter without overload

class A
{
public:
    A();
    A(const A&);
    A(A&&);
    A& operator=(const A&);
    A& operator=(A&&);

    ...
};
void f(const A&); //#1
void f(A&&);      //#2

Is there some way to write #1 and #2 in one function without overloading but achieving the same effect?

As you can see, if there is more than one parameter, I will need to write 2^n overloads.

Aucun commentaire:

Enregistrer un commentaire