B
Brian C
Hello all,
I have a quick question coming from a long time C programmer, trying to
get back into C++. What I want to do is something like (C version):
int OpenLog(char *Filename)
{
FILE *stream;
if((stream=fopen(Filename,"w+"))==NULL)
return(ERROR);
fclose(stream);
return(OK);
}
Obviously this doesn't do much. The key lines are the two return()'s
that would have ERROR and OK defined in some "constants" header file.
In C++, I know you can create static functions that do not require you
to instantiate the class. However, is there a way to do this with
variables? I'd want to initialize them in the header file as well. So
far, all I've come up with is something like:
class Constants
{
public:
enum ReturnCodes
{
Error=-1,
Ok=0
};
....etc...
};
I can reference Constants::ReturnCodes::Error w/o instantiating the
class. Is there another way to do it?
Thanks.
I have a quick question coming from a long time C programmer, trying to
get back into C++. What I want to do is something like (C version):
int OpenLog(char *Filename)
{
FILE *stream;
if((stream=fopen(Filename,"w+"))==NULL)
return(ERROR);
fclose(stream);
return(OK);
}
Obviously this doesn't do much. The key lines are the two return()'s
that would have ERROR and OK defined in some "constants" header file.
In C++, I know you can create static functions that do not require you
to instantiate the class. However, is there a way to do this with
variables? I'd want to initialize them in the header file as well. So
far, all I've come up with is something like:
class Constants
{
public:
enum ReturnCodes
{
Error=-1,
Ok=0
};
....etc...
};
I can reference Constants::ReturnCodes::Error w/o instantiating the
class. Is there another way to do it?
Thanks.