Consider a class with a static member and a static method to set the value of the member (following is based on @JamesKanze 's example ):
class A_EXPORT InA
{
public:
static FILE* ourDest;
static void setDest( FILE& dest );
};
An article (on logging) in Dr. Dobbs would suggest that the static member and static method be combined as follows:
// in header file
class A_EXPORT InA
{
public:
static FILE*& theDest(); // a static member that is a static method too!
};
// in cpp file
FILE*& InA::theDest()
{
static FILE* pStream = stderr;
return pStream;
}
// in user's file
InA::theDest() = fopen("log.txt","a"); //std::ofstream( "log.txt" );
Question: What are the pros and cons of combining a static member and a static method?