Function on lhs of assignment

Hello,

I'm rather new to c++ and today, while trying to find out the best way to write a log handling class, I've stumbled upon theese two code snippets from Dr. Dobb's website (http://www.ddj.com/cpp/201804215?pgno=1):


// Log, version 0.1: a simple logging class
enum TLogLevel {logERROR, logWARNING, logINFO, logDEBUG, logDEBUG1,
logDEBUG2, logDEBUG3, logDEBUG4};
class Log
{
public:
Log();
virtual ~Log();
std::ostringstream& Get(TLogLevel level = logINFO);
public:
static TLogLevel& ReportingLevel();
protected:
std::ostringstream os;
private:
Log(const Log&);
Log& operator =(const Log&);
private:
TLogLevel messageLevel;
};
std::ostringstream& Log::Get(TLogLevel level)
{
os << "- " << NowTime();
os << " " << ToString(level) << ": ";
os << std::string(level > logDEBUG ? 0 : level - logDEBUG, '\t');
messageLevel = level;
return os;
}
Log::~Log()
{
if (messageLevel >= Log::ReportingLevel())
{
os << std::endl;
fprintf(stderr, "%s", os.str().c_str());
fflush(stderr);
}
}


and


Log::ReportingLevel() = logDEBUG2;
const int count = 3;
Log().Get(logDEBUG) << "A loop with " << count << " iterations";
for (int i = 0; i != count; ++i)
{
Log().Get(logDEBUG1) << "the counter i = " << i;
}


I'm shure it's very simple but I do not really understand what's the meaning of this assignment that has a function on it's left hand side:

Log::ReportingLevel() = logDEBUG2;

The function is static, but otherwise looks like a "normal" function ...

Thank you in advance for your help.

f.
It returns a reference to a variable that can be assigned a value.
Topic archived. No new replies allowed.