logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From renny.ko...@rubixinfotech.com
Subject RE: Forward Declaration
Date Fri, 12 Sep 2008 18:16:40 GMT
Stephen - you're right... if the class itself is used, the compiler won't 
know how to construct it... if it is a ptr, it won't complain.

Renny Koshy
President & CEO

--------------------------------------------
Rubix Information Technologies, Inc.
www.rubixinfotech.com



"Stephen Bartnikowski" <sbartnikowski@barkinglizards.com> 
09/12/2008 01:16 PM
Please respond to
"Log4CXX User" <log4cxx-user@logging.apache.org>


To
"'Log4CXX User'" <log4cxx-user@logging.apache.org>
cc

Subject
RE: Forward Declaration






Somebody correct me if I'm wrong, but I don't think it will. In Test.hpp, 
the compiler doesn't know what type LoggerPtr is. Since you're referring 
to that type directly rather than by a pointer, the compiler needs to know 
the full details. It doesn't know that in reality it's a pointer type 
defined elsewhere. If for example, your code instead read:
 
...
class Test {
private:
    static log4cxx::LoggerPtr* _logger;
...
 
then the compiler wouldn't complain.
 
- Stephen

From: Jon Dahl [mailto:jdahl1972@yahoo.com] 
Sent: Friday, September 12, 2008 12:01 PM
To: log4cxx-user@logging.apache.org
Subject: Forward Declaration

Hello,

I'm wondering if it is possible to use forward declaration with log4cxx 
classes in a class header file. I would like to exclude the log4cxx 
headers files in my header files if possible and include the log4cxx 
header files in my cpp(source) files.

Should this work?

// Test.hpp
namespace log4cxx {
class LoggerPtr;
}

class Test {
private:
    static log4cxx:LoggerPtr    _logger;

public:
    Test();
};

//Test.cpp

#include <log4cxx/logger.h>

using namespace log4cxx;

LoggerPtr Test::_logger(Logger::getRootLogger());

Test::Test() {
}

// end test.cpp

Thanks,

-jd-


Mime
View raw message