Hi everybody
I’m just learning how to make classes.
I’ve followed the ofBook OOP chapter but I may have misunderstood something.
I’m trying to transform a function I already have into a class. Its a pretty simple one and I probably didn’t need to do it like so, but if understand how to do this one I’ll be able to do the same with other functions that worth to be transformed into classes.
The original function descends from one in examples/noise. Here it is:
void ofApp::setupNoise(){
// Setup and allocate resources used in the signed noise.
nNoiseData = nDelayFrames;
noiseData = new int[nNoiseData];
for (int i=0; i < nNoiseData; i++){
noiseData[i] = 0;
}
radialNoiseCursor = 0.0;
}
nDelayFrames is an integer passed from outside. 100 e.g.
and here is the derived class header. I think I don’t need a cpp. Is that right?
#ifndef SETUPNOISE_H
#define SETUPNOISE_H
#include "ofMain.h"
class setupNoise {
public:
void setup(){
nNoiseData = 100;
radialNoiseCursor = 0.0;
}
void update(int nNoiseData){
noiseData = new int[nNoiseData];
for (int i=0; i < nNoiseData; i++){
noiseData[i] = 0;
}
}
int nNoiseData; // buffer's size
int *noiseData;
float radialNoiseCursor;
setupNoise();
private: // I couldn't really get what the private functions are for
};
#endif // SETUPNOISE_H
Then I added
#include "setupNoise.h"
and
setupNoise noiseSetup;
in ofApp.h public function
… and in ofApp.cpp setup:
noiseSetup.update(nDelayFrames);
The error I get is (google-translated from German):
error: Undefined reference to `setupNoise :: setupNoise ()
- this weird:
file not found /home/gilfuser/main.cpp
Two questions that arise from the error message are: what is this ` in front of setupNoise? And why it is trying to find main.cpp in the home folder and not in the projects scr folder?
Well, this was longer and had more questions than I thought it would. But I think they are all easy for more experienced users, aren’t they?
Thank you all in advance
best regards,
Gil