I am a newbie so please be easy on me
I have C file...which has following for an example.
Code:
extern int globalvar;
void init()
{
While (something)
{
x++
}
globalvar = x;
}
int getglobalvar (void)
{
return(globalvar);
}
Now I have a C++ file.....
Which I have a function
Code:
void needGlobalvar()
{
int y = getglobalvar()
}
basically I will be then calling this function needGlobalvar in another C++ else....whats the best way I could move the function
Code:
int getglobalvar (void)
{
return(globalvar);
}
to C++ and still have the access to correct information set in the C function for the globalvar
One of my friends said to make the globalvar a singleton and access it so this way it will be safe....could someone please help me with how I could use the sigleton...because I have not done that before.....