If I declare an object in my header file, I get a compilation error. I can, however, construct it in my application's setup() method, simply by calling Analyzer A(44100., "a", 200);
.
If I construct it this way, how do I keep a pointer to it? Won't the object be inaccessible once the constructor call has gone out of scope?
Or, is there another way I should be getting an instance of this object?
(What I'm used to is putting something like Analyzer A;
in my header and then in the cpp putting A = new Analyzer(44100., "a", 200);
. This, though, won't compile.)
Analyzer.hh:
class Analyzer {
public:
/// constructor
Analyzer(double rate, std::string id, std::size_t step = 200);
};
Analyzer.cc:
Analyzer::Analyzer(double rate, std::string id, std::size_t step):
m_step(step),
m_rate(rate),
m_id(id),
m_window(FFT_N),
m_bufRead(0),
m_bufWrite(0),
m_fftLastPhase(FFT_N / 2),
m_peak(0.0),
m_oldfreq(0.0)
{
/* ... */
}
testApp.h:
#include "Analyzer.hh"
class testApp : public ofSimpleApp{
public:
// *This line gives compilation error
// "No matching function for call to Analyzer::Analyzer()"
Analyzer A;
}
testApp.cpp:
void testApp::setup(){
// *This line compiles, but how will I access
//this object outside of current scope?*
Analyzer A(44100., "a", 200);
}