Re: Logging
James Kanze <james.kanze@gmail.com> writes:
Log.cpp: In static member function ???static TLogLevel& Log::ReportingLevel()???:
Log.cpp:18: error: invalid initialization of non-const reference of type ???TLogLevel&??? from a temporary of type ???TLogLevel???
Return a reference to a static variable.
Ok well now I got it, what I still don't get is how to fix this.
I mean if
- I have the definition in the .hpp file, it doesn't find it
- I declare in .hpp file and add a definition in .cpp, it doesn't like
it either
So how am I supposed to write it then?
Managing order of initialization. If the constructor of
a static variable uses your logging facility, it might find that
the variable has not been initialized.
Of course, with an enum type like this, it doesn't matter.
A static variable would be initialized with logERROR. But the
function still allows initialization with any arbitrary default.
I see yes it makes sense then, even if not so intuitive at first sight.
It doesn't change anything with regards to the compiler. If the
class is logically divided into separate sections, however, it
might make sense to respecify access for each section. I've
often duplicated private: this way, e.g.:
class Toto
{
// ...
private: // virtual functions...
virtual void f() = 0;
// ...
friend class Titi;
private: // Except for Titi...
// ...
private: // really
// ...
};
Obviously, Titi can also access "private: // really". The
comments specify intent, and are not in any way enforced by the
compiler. But somehow, I find this clearer in presentation.
Yes sure it's a matter of style also and maybe it dependes on the
particular project also...
And another thing, why the documentation (doxygen style) is normally in
the implementation?
I mean, if I read someone else code then normally I read first the
header, and thus I don't gain much about how it really works.
Unless of course I find where the function is defined or I use doxygen,
which maybe sometimes is not possible...