Problem subclassing classes with protected methods

dermont

18-05-2007 05:15:42

How do I subclass classes with protected methods and/or variable?. In this instance I'm trying to create a Partilce Affector Factory. For example:

OgreStringInterface

class _OgreExport StringInterface
{
protected:

/// Class name for this instance to be used as a lookup (must be initialised by subclasses)
String mParamDictName;

bool createParamDictionary(const String& className)
{
mParamDictName = className;
...

With python-ogre the following test crashes with no createParamDictionary method:

class TestStringInterface(ogre.StringInterface):
def __init__(self):
ogre.StringInterface.__init__(self)
self.createParamDictionary("MyTest")

t = TestStringInterface()
#print dir(t.getParamDictionary())


Partilce Affector Factories

ParticleAffectorFactory
----------------------------
class _OgreExport ParticleAffectorFactory
{
protected:
std::vector<ParticleAffector*> mAffectors;

LinearForceAffectorFactory.h
----------------------------
/** See ParticleAffectorFactory */
ParticleAffector* createAffector(ParticleSystem* psys)
{
ParticleAffector* p = new LinearForceAffector(psys);
mAffectors.push_back(p);
return p;
}
class _OgreExport ParticleAffector : public StringInterface
{
protected:
/// Name of the type of affector, MUST be initialised by subclasses
String mType;


I could hack Ogre with methods for the ParticleAffector such as the following:

void pushBackAffector(ParticleAffector* p)
{
mAffectors.push_back(p);
}

ParticleAffector(ParticleSystem* parent, String& name): mParent(parent),mType(name) {}


However, it appears there are so many such instances that obviously I must be doing something wrong.

roman.yakovenko

20-05-2007 09:41:15

How do I subclass classes with protected methods and/or variable?. In this instance I'm trying to create a Partilce Affector Factory.
....
However, it appears there are so many such instances that obviously I must be doing something wrong.


Python-Ogre doesn't expose non-public non-pure virtual member functions:

http://python-ogre.org/browser/trunk/python-ogre/code_generators/ogre/generate_code.py
Take a look on line 559.

Obviously we should change this behavior. Please open a bug on the site.

Thanks

dermont

23-05-2007 06:26:06

Thanks for the reply. It appears that the current SVN has already been updated so I didn't open a bug report. As for the PartilceAffector Factory, I created a plugin instead.