Weirdly enough, I’m having some success when I just keep all of my functions for a class inside the h file and don’t include ofMain.h
I created a test file with this class in a file named Ball.h
#ifndef emptyExample_Ball_h
#define emptyExample_Ball_h
class Ball{
public:
int size;
ofPoint pos;
void setup(int _size, float x, float y){
size=_size;
pos.set(x,y);
}
void draw(){
ofSetColor(255,0,0);
ofCircle(pos.x, pos.y, size);
}
};
#endif
This compiles and runs just fine. In testApp.h I am including “Ball.h” and my testApp.mm looks like this:
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(127,127,127);
myBall.setup(30, 50, 50);
}
//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
myBall.draw();
}
(The other standard OF functions are there, but this is the only part that I changed at all)
I would have thought that not including “ofMain.h” in my Ball class would have caused issues, but it doesn’t seem to.
This method did not work at all when I tried making Ball.cpp. I immediately started getting the errors I was expecting to get when I put everything in the H file. Not including “ofMain.h” caused unknown type errors and unknown identifier errors.
Here is the code I used there
Ball.h:
#ifndef emptyExample_Ball_h
#define emptyExample_Ball_h
class Ball{
public:
void setup(int _size, float x, float y);
void draw();
int size;
ofPoint pos;
};
#endif
Ball.cpp:
#include "Ball.h"
void Ball::setup(int _size, float x, float y){
size=_size;
pos.set(x,y);
}
void Ball::draw(){
ofSetColor(255,0,0);
ofCircle(pos.x, pos.y, size);
}
Attached are two screen shots of the errors I’m getting:

