N
nin234ATIyahoo.com
Hi all
I have a logger class and facing the following issue
enum eErrLvl
{
eLOG_DEBUG_5 = 1,
eLOG_DEBUG_4,
eLOG_DEBUG_3,
eLOG_DEBUG_2,
eLOG_DEBUG_1,
eLOG_INFO,
eLOG_WARNING,
eLOG_ERROR,
eLOG_FATAL
};
std:stream&
operator << (std:stream& os, eErrLvl& eLvl)
{
switch (eLvl)
{
case eLOG_DEBUG_5:
os << "Debug_5\t: ";
break;
case eLOG_DEBUG_4:
os << "Debug_4\t: ";
break;
case eLOG_DEBUG_3:
os << "Debug_3\t: ";
break;
case eLOG_DEBUG_2:
os << "Debug_2\t: ";
break;
case eLOG_DEBUG_1:
os << "Debug_1\t: ";
break;
case eLOG_INFO:
os << "Info\t: ";
break;
case eLOG_WARNING:
os << "Warn\t: ";
break;
case eLOG_ERROR:
os << "Error\t: ";
break;
case eLOG_FATAL:
os << "Fatal\t: ";
break;
}
return os;
}
class srvLog
{
static int volatile nLglvl;
//volatile keyword is a hint to compiler an object may change the
value
//in a way not specified by the language and aggressive
optimizations
//must be avoided
eErrLvl nSeverity;
public:
friend std:stream& operator << (std:stream& , const
srvLog&);
};
std:stream& operator << (std:stream& os, const srvLog& oLog)
{
os << "initial msg " << static_cast<eErrLvl>(oLog.nSeverity);
return os;
}
My problem is with this statement
os << "initial msg " << static_cast<eErrLvl>(oLog.nSeverity);
Only when I use the static_cast does it invoke the operator (<<) for
the enum. Otherwise it just prints the integer value corresponding to
the enum
ie if I use
os << "initial msg " << (oLog.nSeverity);
Ninan
I have a logger class and facing the following issue
enum eErrLvl
{
eLOG_DEBUG_5 = 1,
eLOG_DEBUG_4,
eLOG_DEBUG_3,
eLOG_DEBUG_2,
eLOG_DEBUG_1,
eLOG_INFO,
eLOG_WARNING,
eLOG_ERROR,
eLOG_FATAL
};
std:stream&
operator << (std:stream& os, eErrLvl& eLvl)
{
switch (eLvl)
{
case eLOG_DEBUG_5:
os << "Debug_5\t: ";
break;
case eLOG_DEBUG_4:
os << "Debug_4\t: ";
break;
case eLOG_DEBUG_3:
os << "Debug_3\t: ";
break;
case eLOG_DEBUG_2:
os << "Debug_2\t: ";
break;
case eLOG_DEBUG_1:
os << "Debug_1\t: ";
break;
case eLOG_INFO:
os << "Info\t: ";
break;
case eLOG_WARNING:
os << "Warn\t: ";
break;
case eLOG_ERROR:
os << "Error\t: ";
break;
case eLOG_FATAL:
os << "Fatal\t: ";
break;
}
return os;
}
class srvLog
{
static int volatile nLglvl;
//volatile keyword is a hint to compiler an object may change the
value
//in a way not specified by the language and aggressive
optimizations
//must be avoided
eErrLvl nSeverity;
public:
friend std:stream& operator << (std:stream& , const
srvLog&);
};
std:stream& operator << (std:stream& os, const srvLog& oLog)
{
os << "initial msg " << static_cast<eErrLvl>(oLog.nSeverity);
return os;
}
My problem is with this statement
os << "initial msg " << static_cast<eErrLvl>(oLog.nSeverity);
Only when I use the static_cast does it invoke the operator (<<) for
the enum. Otherwise it just prints the integer value corresponding to
the enum
ie if I use
os << "initial msg " << (oLog.nSeverity);
Ninan