Inheritance of blueprint<character> or character class

ocrim74

16-01-2007 16:20:54

Hi,

I wrote the following post to the following topic yesterday. May be no one recognized it. ;-)

http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=3169

The way to inherit the character class really works, but only if I change the library. That means to declare only the constructor as protected, than as private.

Now I worked on inheritance of the blueprint<character> and I am able to compile but not sure if I did the inheritance the right way.

Did anyone try something like this?

Thanks,

ocrim74

betajaen

16-01-2007 16:55:22

Inheriting the blueprint character template should be fine, I assume you did it this way?

template<>
class blueprint<superCharacter> : public blueprint<character> {

friend character;

public:


blueprint<superCharacter>(){
setToDefault();
// Your setup code goes here
}
};

ocrim74

16-01-2007 17:16:32

Hi,

thanks for the quick answer! ;-)

Is it right that the superCharacter-class should be an inherited class from the character class? If i have to inherit the character-class I think I will have the problem that I can not access the constructor of the character-class declared as private. I that right?

I am not sure, may be I missunderstand the idea of the code. ;-)

Thanks,

ocrim74

betajaen

16-01-2007 17:27:57

Well in theory passing on the superBlueprint to a superCharacter that inherits the character class it should work, assuming that the casting is correctly done.

But there is a reason why the constructor is private:



superCharacter* blueprint<superCharacter>::create(Ogre::String _name, Ogre::Vector3 _pos, scene *_scene) {
superCharacter* sp = new superCharacter(_name, _pos, this, _scene);
_scene->createCharacter(static_cast<character*>(sp));
return sp;
}

...

superCharacter::superCharacter(
Ogre::String _name,
Ogre::Vector3 _pos,
blueprint<character> *_bp,
scene *_scene)
: character(_name, _pos, static_cast< blueprint<character> >(*_bp),_scene) {
//
mHairColour = _bp.hairColour
}

ocrim74

19-01-2007 14:02:01

Hi,

I tried the code and it looks fine.

superCharacter::superCharacter(
Ogre::String _name,
Ogre::Vector3 _pos,
blueprint<character> *_bp,
scene *_scene)
: character(_name, _pos, static_cast< blueprint<character> >(*_bp),_scene) {
//
mHairColour = _bp.hairColour
}


The only problem is the casting. Do I need to implement the casting operator ">"?

I got the following message while compiling:

error C2440: 'static_cast' : cannot convert from 'nxOgre::blueprint<nxOgre::character>' to 'nxOgre::blueprint<nxOgre::character> *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


I have not so much practice in casting like this. Are there any examples in the tutorials?

I would be :D if you can help me.

Thanks in advance!

ocrim74

betajaen

19-01-2007 14:46:42

1. It seems that a * is missing on the character on that line. If you post the line which the error is talking about I'll fix it.

2. There isn't any examples of static_casting or casting in NxOgre, as it's not really in the scope of the tutorials, and any casting is handled by NxOgre anyway. I suggest if you are quite confused about it, there are a few online C++ books which would teach you about it.

ocrim74

19-01-2007 14:49:57

I tried something that I tried before, but now together with your code.

VXP_Character::VXP_Character(
Ogre::String _name,
Ogre::Vector3 _pos,
blueprint<character> *_bp,
scene *_scene)
: character(_name, _pos, _bp,_scene) {
//mHairColour = _bp->hairColour
}


I do not really unterstand why I need the cast of the type? In my opinion the "VXP_Character"-constructor and the Character-contructor have the same "blueprint<character> *"-type of parameter at the third position.

If I use the code above I get no problem with the type, but I get the following message:

VXP_Character.cpp(25) : error C2248: 'nxOgre::character::character' : cannot access private member declared in class 'nxOgre::character'


I don´t understand if there is a difference in this problem if I do the static-cast.

It is still working if I declare the constructor for the character not as private.

HELP! ;-)

Thanks,

ocrim74

ocrim74

19-01-2007 14:51:22

Oops, our messages crossed each other. ;-)

It´s talking about the error in line:

character(_name, _pos, static_cast< blueprint<character> >(*_bp),_scene)

betajaen

19-01-2007 15:49:22


character(_name, _pos, static_cast< blueprint<character*> >(*_bp),_scene)


If your getting private errors, then just cheat and change the character constructor to protected or public. :wink:

ocrim74

21-01-2007 16:27:12

Hi,

sorry for beeing so stubborn. ;-)

If I try to compile with the following code I get an error:

character(_name, _pos, static_cast< blueprint<character*> >(*_bp),_scene)

error C2440: 'static_cast' : cannot convert from 'nxOgre::blueprint<nxOgre::character>' to 'nxOgre::blueprint<T>'
with
[
T=nxOgre::character *
]
No constructor could take the source type, or constructor overload resolution was ambiguous


Anyways, I still get private errors. If I declare the constructor as protected it works with my old idea.

The problem is that I want do distribute the software to some partners of our project. It is important for me to have a clear software-design. I do not want to change the library. If I change the library I must create and distribute my own nxOgre.dll. It might cause version conflicts if the people use the wrong version. Another problem is that I have to cheat every new version of nxOgre for my purposes.

I think it´s not unusual that I want to inherit from the character to customize it. Can you tell me the idea of the concept? Why is the constructor of the character declared as private? You said that there is a reason, but I do not understand it. I thougt it would be accessable through the blueprint-class, but this does not seem to work without changing the library.

Is there any idea in the architecture that I do not understand?

Thank you and have a nice Sunday,

ocrim74