Background : The ampersand in "log4cpp::Category& category = ..." is beyond my knowledge. I am actively learning C++, but I am still very inexperienced. I am trying to build my own logging class that utilizes log4cpp logging facilities. log4cpp works fine for me if I implement a simple example in main(), but I (strategically) want the simplification of my own custom class that isolates my log4cpp code use into one simple class (involving only one .h and one .cpp source).
Need : I need to split my log4cpp component definitions and declarations between A) a header file and B) constructor and member functions. I do not fully understand the instantiation of the "category" object in the "Category.hh" header, or example, so I am not succeeding in splitting-out the "category" object to header-based definition(s) vs. its instantiation/initialization instructions. The ampersand character in "log4cpp::Category& category =" is completely loosing me. My mind is trying to "take the address of …" with the ampersand syntax. Please advise me. I am hopelessly lost (I have reviewed the Category.hh header source). Thanks for any help you can provide!!!
My Feable Attempts to Split "Category" Definition from Declaration
(same headers as example above)
class eLog
{
private:
log4cpp::Appender *appender;
log4cpp::Layout *layout;
log4cpp::Category category; (this is not working, just an attempt)
...
}
…
eLog::eLog()
{
appender = new log4cpp::FileAppender("FileAppender",LOGFILE);
layout = new log4cpp:impleLayout();
category.getInstance("Category"); (this is not working, just an attempt)
public:
/**
* Return the root of the Category hierarchy.
*
* The root category is always instantiated and available. It's
* name is the empty string.
* Unlike in log4j, calling Category.getInstance("")
* does retrieve the root category
* and not a category just under root named "".
* @returns The root category
**/
static Category& getRoot();
...
/**
* Instantiate a Category with name name. This
* method does not set priority of the category which is by
* default Priority::NOTSET.
*
* @param name The name of the category to retrieve.
**/
static Category& getInstance(const std::string& name);
...
Summary : How do I split the Category definition and declaration??? Thanks for any help you can provide!!!
I don't understand what you are trying to split. It seems that what you are doing is wrapping things into a class.
Any way, read something about references, then read about initializer lists. That should explain how to use a reference here.
Though you could get by with a pointer (probably even with a normal variable, but that might cause problems. I can't say for sure, because I've never used log4cpp)