1

Suppose I have a function like this:

void MyFun(MyClass* p){

}

Where p is actually an unknown length array. How can I overloaded it to accept an array of rvalue MyClass.

J. Doe
  • 572
  • 1
  • 3
  • 11

1 Answers1

0

Basically, you cannot - since being an rvalue is not really a proper part of the type system. There's no "pointer to rvalue T" or anything like that. Also, because using a pointer means that the pointed-to object could be any subclass of MyValue (that is also a reason I would not try something like reinterpreting the pointer as an std::array<MyClass, 123>, even if I knew the length to be 123).

I suggest you wrap your raw array in some class (dumb name for it: BunchOfMyClasses), and have:

void MyFun(const BunchOfMyClasses &);
void MyFun(BunchOfMyClasses &&);

as the overloads.

einpoklum
  • 102,731
  • 48
  • 279
  • 553