Hi!
I have some classes of objects always been updated from cycles in the App.
I need to get some string values that are added inside the objects.
Is it possible to get these string values in ofApp?
Thanks.
Hi!
I have some classes of objects always been updated from cycles in the App.
I need to get some string values that are added inside the objects.
Is it possible to get these string values in ofApp?
Thanks.
Add a public get method:
in .h
class Foo
{
public:
string getBoo();
private:
string m_booValue;
};
in .cpp
string Foo::getBoo()
{
return m_booValue;
}
you can use ofGetAppPtr() which returns a pointer to your app. youâll need to cast it to ofApp though since OF canât know before hand about the specific app class:
((ofApp*)ofGetAppPtr())->someString;
itâs cleaner, though, to pass the values you need to the object when calling itâs setup or update from ofApp, for example, like:
obj.update(someString);
if you need to pass several values and donât want to have that many arguments you can group them in a struct like:
struct AppState{
string someString;
int someInt;
}
class ofApp{
....
AppState state;
}
// in update:
obj.update(state);
OF is quite new for me⌠so, in class.h Iâve stated:
if (someBool == true) {
((ofApp*) ofGetAppPtr())->someGlobalString = objectString;
}
at ofApp.cpp:
include âclass.hâ
cout << âgetStringFromObject:â << someGlobalString <<endl;
why is âofAppâ undeclared identifier ?
I have all the funtionâs class in one header file, no cpp⌠maybe itâs missing the include âofAppâ cause I canât included in the .h ?
yes thatâs another problem of using that function, since you are using the object from ofApp and ofApp from the object, if you try to include ofApp.h from the object .h youâll get a recursive include and it wonât compile. you need to use a cpp and only include ofApp.h there
Problem solved!
Opted for the simplest mode, ofGetAppPtr.
A little bit struggle to separate all class files, there are a lot. Strings coming from vectors, feeding dynamic menus, floats and GPS data spreading points to a virtual 3D city map, all data loaded from a csv database file. Beautiful to see all working action. Great OF ! Love this C++ clambering.
Iâll be sending link as soon as I have an online reel.
Thank you all.