Making classes in openframeworks in 2015 vs

I’m having problems creating classes of my own in openframeworks. For some reason my class is not being found by visual studios. I basically followed and even copied the tutorial on the website. It wasn’t fixed. This may be a bug.

http://openframeworks.cc/tutorials/first%20steps/003_ooops_object_oriented_programming.html

Where is your class located? is it in the src folder and added to your project properly?

What version of openframeworks are you using? note that 0.8.4 only runs with the VS 2012 toolset so if you’re getting errors it could very well be that your using the wrong version.

I usually add a class but it is not recognized. Basically I’m using the newest build of open frameworks that works with visual studio 2015. This is my class

#include “ofMain.h”

class ofClass
{
public:
float x;
void test();
};

#include “ofClass.h”

void ofClass::test()
{
std::cout << “works”;
};

#ifndef _OF_CLASS
#define _OF_CLASS

#include “ofMain.h”

class ofApp : public ofBaseApp{

public:
	void setup();
	void update();
	void draw();

	void keyPressed(int key);
	void keyReleased(int key);
	void mouseMoved(int x, int y );
	void mouseDragged(int x, int y, int button);
	void mousePressed(int x, int y, int button);
	void mouseReleased(int x, int y, int button);
	void mouseEntered(int x, int y);
	void mouseExited(int x, int y);
	void windowResized(int w, int h);
	void dragEvent(ofDragInfo dragInfo);
	void gotMessage(ofMessage msg);

};

#endif

Please try like this:

ofClass.h:

class ofClass {
public:
	ofClass();
	~ofClass();
	float x;
	void test();
};

ofClass.cpp

#include "ofClass.h"

ofClass::ofClass() {

}

ofClass::~ofClass() {

}
void ofClass::test() {
	std::cout << "works";
};

ofApp.h

#pragma once
#include "ofMain.h"
#include "ofClass.h"

class ofApp : public ofBaseApp {

public:
	...

	ofClass MyClass;
};

ofApp.cpp


void ofApp::setup(){
	MyClass.test();
}

You will see works on console window.
Please use markdown syntax for your code.^^

1 Like

I works. I literally have to put it in the src file. Visual studio puts it in the root and this becomes a problem when searching for the method. Thanks for your help.