0

Header file prototype (.hpp) is giving a g++ compiler error - no matching function type in header file. What it the correct way to write the prototype (or function parameter)? I've tried oh so many combinations...

void myClass( Objects (*)[] );

Implementation file function definition (.cpp)

void myClass::myFunction( Objects *ptr2object_Array ) {

  /* do stuff */ }

Looked thoroughly for the answer here and elsewhere... Thanks. Aware of the vector lecture, I'm stuck with an array of object pointers.

4
  • 1
    Is there any reason you need to be passing around C style arrays, rather than e.g. std::array or std::vector? Commented Feb 10, 2016 at 21:36
  • 1
    Objects (*)[] is not the type of an array of object pointers; it's the type of a pointer to an array of objects. Commented Feb 10, 2016 at 21:47
  • @Cubic - I'm not sure what the difference is on C style arrays. It's an array of pointers to inherited class objects of an abstract class, if that helps... Commented Feb 10, 2016 at 22:31
  • @Chris The difference is that C++ vectors and arrays are easier to use and don't require weird syntax that has you second guessing all the time. Commented Feb 10, 2016 at 22:50

1 Answer 1

3

The function signatures need to match exactly:

void myClass( Objects (*)[] );

void myClass::myFunction( Objects (*ptr2object_Array)[] ) {

  /* do stuff */ 
}

Simple pointers like Objects *ptr2object_Array aren't the same as arrays of pointers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks!! I knew that, but just couldn't get the right combo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.