-2

so was trying to make an array of pointers to objects and pass it to a function but am getting errors. i have declared an array.

shapes *myArray[2];

having a function

void addShape(shapes *myArray[]);

passing the array

addShape(myArray);

isnt working. error: argument of type "int *" is incompatible with parameter of type "int **".

what to do here?

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • You are the one millionth person on Stackoverflow wondering why arrays cannot be passed by value to a function. If I take **your exact question title** and paste it into the Google search text field, then the very first hit leads me to a Stackoverflow question which answers everything you are asking. – Christian Hackl Mar 07 '16 at 19:00
  • [Cannot reproduce](http://coliru.stacked-crooked.com/a/f9205d0ec675c1b3). Please post a [mcve]. – Baum mit Augen Mar 07 '16 at 19:11
  • Possible duplicate of [array of pointers as function parameter](http://stackoverflow.com/questions/1719051/array-of-pointers-as-function-parameter) – Oden Mar 07 '16 at 19:22

1 Answers1

2

It should be

void addShape(shapes* (&myArray)[2]);

More intuitive with std::array<shapes*, 2> of std::vector<shape*>

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • It might make more sense to OP if you explain what `shapes *myArray[]` means as a function parameter :-) – juanchopanza Mar 07 '16 at 18:45
  • this was an assignment where i was supposed to create an array of pointers . and a function to add shapes onto that array – Shamiso Mar 07 '16 at 18:52
  • I don't quite understand this answer, but I may have misunderstood the question in the first place as I cannot reproduce the problem. – Baum mit Augen Mar 07 '16 at 19:12