PandaNode as C++ EventParameter

Hello, me again with another newbie C++ question, this time regarding inheritance.

I have a C++ class (FooNode) derived from PandaNode. Now I want to send events with FooNode* as parameter using event->add_parameter( EventParameter( node ) );

The problem is that EventParamter can be int, float, string and TypedReferenceCount. TypedReferenceCount is a Panda3D utility class which combines TypedObject and ReferenceCount in one class. PandaNode inherits from both, TypedObject and ReferenceCount, but not from TypedReference count.

Declaring FooNode like this doesn’t work because of ambiguousness.

class FooNode : public PandaNode, public TypedReferenceCount {...

Is there a way to make FooNode derive from TypedReferenceCount?

The only workaround I know is to create a separate class FooNodeParam class which can be passed as parameter and “contains” a FooNode:

class FooNodeParam : public TypedReferenceCount {
  FooNode *node;

Any other ideas?


virtual inheritance like this doesn’t help too:

class FooNode : public PandaNode, public virtual TypedReferenceCount {...

VC8 complains about “error C2385: ambiguous access of ‘ref’”.

Yep, this is the workaround we have already employed within Panda. We have defined the EventStorePandaNode class (defined in pgraph/eventStorePandaNode.h) which does exactly this.

To use it, you would do something like:
event->add_parameter(EventParameter(new EventStorePandaNode(node)));


Wow, thanks for the fast answer. I will do the same.