Hello guys!
I am having some problems getting the value of a slider which is defined in the class ofapp from another class…
My code is here:
//ofApp.h
#include "ofMain.h"
#include "ofxGui.h"
#include "ofxInputField.h"
#include "Myclass.h"
class ofApp : public ofBaseApp {
public:
int getpulso();
MyThread thread;
private:
ofxIntSlider pulso;
};
//ofApp.cpp
int ofApp::getpulso(){
return pulso;
}
//My new class…
#pragma once
#ifndef MyClass_H_
#define MyClass_H_
class ofApp;
class MyThread : public ofThread {
ofApp aplicacion;
public:
int pulso = aplicacion.getpulso;
};
#endif
And errors:
Dorald
October 29, 2016, 1:28pm
#2
pulso is private member of ofApp class and cannot access from another class.
1 Like
Thanks for your answer, but even so I have the same error messages.
Reading error messages, I think that the problem could be that the class ‘ofApp’ isn’t defined… but I don’t know how to define it…
@Dorald have you seen another error?
zach
October 30, 2016, 11:27am
#4
usually what I do is use ofGetAppPtr(), in the secondary .cpp code. this returns the pointer to the baseApp and you can cast it as an ofApp ptr.
#include "ofApp.h"
((ofApp *) ofGetAppPtr())-> getpulso();
you can’t include ofApp.h in the h file because you will have cyclical includes, but you can do this in the .cpp file.
zach
October 30, 2016, 11:28am
#5
ps: this forum thead might help
the easiest way to do this is either pass the value through to the wave object from ofApp, or in the .cpp file of wave (you can’t do this in the .h file) you can do:
#include "ofApp.h" // note you can't do this in wave.h b/c it would be a recursive include...
then later in the cpp you can do:
((ofApp*) ofGetAppPtr())->waveSpeed
ofGetAppPtr() gets a pointer to the app that OF is running (ie, ofApp) and (ofApp*) casts it as an ofApp (it’s a pointer to an ofBaseApp). I use ofGetAppPtr() to…