Hi Allen,
In Java, only push/pop can be used because objects are not automatically
destroyed at the end of the scope. For log4cxx, the
constructor/desctructor approach was probably added for convenience (to
be completely log4j compatible the constructor and destructor should
not even be public ;-) )
Looking into ndc.h, the push method is overloaded like
#if LOG4CXX_HAS_WCHAR_T
static void push(const std::wstring& message);
#endif
static void push(const std::string& message);
and I think this was simply missed for the constructor. Since
the constructor only calls push(), you can try if the attached
patch solves your issue.
Best Regards,
Andreas
Conway Allen wrote:
With the 0.9.7 i've been writing NDC ndc(mystring) where mystring is
some std::string or a const char*. I find that with the 0.9.8 I can't do
that - the compiler tells me that the only constructor I can use is a
copy constructor or one that takes a const LogString& which seems to be
a basic_string<wchar_t> or something like that. It is possible, however
to invoke NDC::push(mystring) but then you lose the advantage having the
destructor popping what was pushed. Is this how things are meant to be?
--
Andreas Fester
mailto:[EMAIL PROTECTED]
WWW: http://littletux.homelinux.org
ICQ: 326674288
Index: include/log4cxx/ndc.h
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/include/log4cxx/ndc.h,v
retrieving revision 1.15
diff -u -r1.15 ndc.h
--- include/log4cxx/ndc.h 4 May 2005 16:13:40 -0000 1.15
+++ include/log4cxx/ndc.h 21 Jul 2005 20:27:39 -0000
@@ -112,7 +112,11 @@
public:
typedef std::stack<DiagnosticContext> Stack;
- NDC(const LogString& message);
+#if LOG4CXX_HAS_WCHAR_T
+ NDC(const std::wstring& message);
+#endif
+ NDC(const std::string& message);
+
~NDC();
/**
Index: src/ndc.cpp
===================================================================
RCS file: /home/cvspublic/logging-log4cxx/src/ndc.cpp,v
retrieving revision 1.15
diff -u -r1.15 ndc.cpp
--- src/ndc.cpp 11 Mar 2005 06:34:49 -0000 1.15
+++ src/ndc.cpp 21 Jul 2005 20:27:39 -0000
@@ -47,7 +47,14 @@
return *this;
}
-NDC::NDC(const LogString& message)
+#if LOG4CXX_HAS_WCHAR_T
+NDC::NDC(const std::wstring& message)
+{
+ push(message);
+}
+#endif
+
+NDC::NDC(const std::string& message)
{
push(message);
}