I have an Objective-C++ file, and I have two classes: one Objective-C, one C++:
@implementation ClassA
....
// Create a copy of MyClass and use it in another C++ class
instanceOfCppClassB->callFunction(new MyClass);
@end
class MyClass : public AnotherClass
{
....
};
This compiles and runs fine with the C++ class up on top, but I’d like to move it to the bottom. When I move it to the bottom I get the error:
Invalid use of incomplete type ‘struct MyClass’
Forward declaration of ‘struct MyClass’
Regardless of using typedef,struct,@class I get no love. How do I forward declare this class?
Forward declaration of a C++ class does not allow you to use instances of the class, you can just pass them around. (To simplify the example, I have omitted any Objective-C.)
You must put the entire definition of a class before you use it. The forward declaration only allows you to declare variables using the class’s type.
So the answer is: what you ask is impossible. (What is wrong with putting the class definition at the top, anyway?)
You can still put methods at the bottom: