Dor
Dor

Reputation: 11

Declare a struct defined in class

There is a header file:

class btCollisionWorld
{
public:

    struct RayResultCallback{
        int something; //example only
    };
)

I'm writing another headeer file, where I want to use pointer to btCollisionWorld ::RayResultCallback, but I don't want to include whole btCollisionWorld.h (I will include it in my cpp file)

How do I declare it properly?

I've tried this and it fails:

class btCollisionWorld;
struct  btCollisionWorld::ClosestRayResultCallback;

Upvotes: 1

Views: 1423

Answers (2)

leftaroundabout
leftaroundabout

Reputation: 120751

It's only reasonable to keep this other file seperated from the btCollisionWorld.h if it does not really rely on the specific class btCollisionWorld, but rather just on some class with certain properties which btCollisionWorld fulfills. In this case, it might be better to keep it generic, that is: rather than using a btCollisionWorld* you may do

template <typename btCollisionWorldT>
whatever-kind-of-structure-it-is {
  btCollisionWorldT * genericpointer;
}

If the structure is a class, you can later typedef it so that btCollisionWorldT is btCollisionWorld in every actual instance of this class.

Alternatively you can use a void*, but that is less likely to be the ideal solution.

Upvotes: 0

Thomas
Thomas

Reputation: 10708

You can't declare a struct defined inside a class without defining the containing class. You can use a namespace to achieve a similar goal.

Upvotes: 6

Related Questions