I have an array of pointers declared as a member of a class as follows:
class Bar { private: static constexpr int SIZE = 10; Foo* m[SIZE]; }
In one of my class methods, I would like to return a pointer (or, preferably, a link) to this array. The array has a known size at compile time, but I keep track of how many items I placed there (this is buffer material).
What is the best way to return a reference to this array in C ++ 11?
Here is what I tried:
GetArray(Foo* &f[], unsigned &size) const
I like the syntax because it makes it clear that the reference value is an array of pointers, but it gives a compiler error: Declared as array of references of type Foo*
GetArray(Foo** &f, unsigned &size) const { f = m; size = mSize; }
Gives me: Error: assignment Foo **' from incompatible type Foo *const[10] . Throwing mFoo to (Foo**) fixes the error, but IMHO, this is not elegant.
source share