Re: passing array of floats (or vectors) into another function - data
scope - hmmm. Very ugly...
On Oct 17, 9:20 pm, someone <newsbo...@gmail.com> wrote:
[snip]
Maybe it's a simple question for you... When I wrote the first post, I
confused myself a bit. I still think this is not very C++'ish, but
it's the best I can do now, but I would like to learn from someone
here if you have better suggestions :-)
Thanks for any comments, if you like... If not, then this is the way
it's gonna be - it works :-)
Adding to what Victor said, I've looked at the interface, and I think
this is a better example of what you should do. I've replaced the
library classes with my own placeholders. Note that no private
data exists. This compiles and runs fine courtesy of ideone.
#include <vector>
struct mglGraph
{
};
struct xresReader
{
std::vector<float> RTTime;
std::vector<std::vector<float> > RTSensor;
};
class mglGraphAB
{
public:
void Window(
int argc, char **argv, int (*draw)(mglGraph *gr, void *p),
const char *title, void *par=NULL, void (*reload)(int
next)=NULL )
{
//For example, what library code might look like...
mglGraph gr;
draw( &gr, par );
}
};
int mysample_impl( mglGraph*, xresReader* )
{
//Do work here!!! All xresReader data available...
return 0;
}
int mysample( mglGraph *gr, void* param )
{
//Delegate work to ...impl.
return mysample_impl( gr, static_cast<xresReader*>( param ) );
}
int main( int argc, char **argv )
{
//[snip]
//Ensure scope of xresReader exceeds that of mglGraphAB.
//They might be encapsulated in a class as members...
xresReader myBinReader;
mglGraphAB gr;
gr.Window( argc, argv, mysample, "My Window", &myBinReader );
return 0;
}