Extending ofNode class

Hello Of users!

Completely new to OF, I am testing basic class inheritance. (By the way, thank you for this OfBook projet which is a great tool)
I would like to extend the ofNode class to take advantage of its postionning methods.
Here is a basic example of an inherited class called “element”


#pragma once

#include "ofMain.h"

class element: public ofNode {


float posX, posY, posZ;
void setup(float px, float py, float pz);
void customDraw();



#include "element.h"


void element::setup(float px, float py, float pz){
posX = px;
posY = py;
posZ = pz;
this->setPosition(posX, posY, posZ);

void element::customDraw(){
ofDrawBitmapString(ofToString(this->getX()), 20, 20);

in ofApp.h:

element myElement;

in ofApp.cpp:

void ofApp::setup(){
myElement.setup(100, 200, 0);

void ofApp::draw(){

This code compiles but I get an EXC_BAD_ACCES when calling any of the base class member functions.
In this example, the warning occurs next to the onPositionChanged() in ofNode.cpp
Can I ask you what I am doing wrong?

I tried your code and it works fine, no errors and no warnings. I could call a method of ofNode (orbit()) without any problem. What version of oF are you using?

Hello Elaye, thank you for your help. I was using the 0.8.4 release 2.
I think I will completely reinstall as I can’t figure it out.
Thanks again for your code check!

before you re-install, can you try rebuilding your project – ie, hitting clean and recompiling. sometimes you can see voodoo if your compiled objects get out of date. most compilers are good about this (ie, the will recomile things when it’s good to), but from time to time, an old .o file will be mixed in with a newer .h and you get weird moments like this.

Thanks for the tip Zach.
Cleaning and recompiling in xcode solved this.