Porting question with isKindOfClass and overal class handling differences



I hope someone will be able to help me with this c*+ question.
I’m porting code responsible for enabling and disabling elements on screen during screen transitions.
Anyway… I’ve got this piece of code in CCNode category which performs following checks:

  • enableMenus:*enable ofNode:node {
    node).children) {
    if {
    for result).children) {
    if {
    result1).isEnabled =enable;
    The rest of the method are just similar checks for different classes.
    Is it possible to achieve this using c
    +? How can I do it? If not, what should I do to have similar check?

Another thing I have stumbled upon during porting was this piece of code from another CCNode category:

self.grid = [[grid_ class] gridWithSize:grid_.gridSize];

I’ve changed that to be:

m_pGrid = (m_pGrid->gridWithSize(m_pGrid->getGridSize()));

but I’m not sure if this is the correct way to do it :confused:

Any help will be appreciated.

Thanks a lot!


Try looking for dynamic_cast, I think the syntax is like this YourClass* myClass = dynamic_cast(YourClass) someClass;


The RTTI mechanic that C++ uses is not portable and is not recommended. The latest version of cocos2d-x does mention a new simple RTTI feature. Although I cannot find any documentation, this new feature may be what you are looking for.