Hi, I have the following problem: I have a singleton of a class and this class has just NEN <<operator. But while compiling I get the following error: Code: error C2296: '<<' : illegal, left operand has type 'class CLog *' error C2297: '<<' : illegal, right operand has type 'char [5]' Here's the code: Code: // CLog.h class CLog { public: static CLog *getInstance (void) { return (&m_Instance); } void setFile (const char *FileName = "Protokoll.htm"); CLog& operator<< (void* n); private: CLog (void); static CLog m_Instance; std::ofstream m_Stream; }; the cpp: Code: #include "CLog.h" CLog CLog::m_Instance; CLog::CLog(void) { } CLog& CLog::operator<< ( void* n ) { this->m_Stream << n; return (*this); } and here the main.cpp: Code: #include "CLog.h" int main (void) { CLog *p_Protokoll; p_Protokoll = CLog::getInstance (); p_Protokoll << "Test" << std::endl; return(false); } I have to rebuild the Singleton or how I get the <<operators, to the run it? : Confused:
you work with in the refernzen or dereferenzierst pointer Code: int main (void) { CLog *p_Protokoll; p_Protokoll = CLog::getInstance (); *p_Protokoll << "Test" << std::endl; return(false); } ahja Code: CLog *p_Protokoll; p_Protokoll = CLog::getInstance (); Although this rule does not apply when buldins, the link is preventive false becomes a convertiert and returned in the return-value of main means anything other than 0, but an error
Thanks for the info. would put on the change, oh yeah, this is the pointer just fine, but no gibbet "elegant" solution? For write this is extremely ugly at the beginning: Code: *p_Protokoll << "Test" << "test2"; Is there the possibility that some things done this: Code: Protokoll << "Test" << "Test2";
Code: CLog & Protokoll = *CLog::getInstance(); I would also modify the type of return of getInstanz from pointer to reference
Hm, so I've now made the getInstance Ner reference, but there are still errors. Code: static CLog &getInstance (void) { return (m_Instance); } and I get on the line here: Code: CLog &Protokoll = *CLog::getInstance(); this error: Code: error C2100: illegal indirection
sorry but your operator <<is the biggest waste. Look at you n little in STL Source to take next, or the best book on hand.