Posted by
Boris Skorodumov on
URL: http://quantlib.414.s1.nabble.com/Settings-instance-evaluationDate-produces-exception-in-managed-code-tp7848p7852.html
>Wait, I didn't quite get the last part. With the code as it is now, it
>doesn't work in either way. For it to work, you have to comment out the
">inline" on line 70. Is this correct?
No, I do not need to touch singleton.hpp at all in order to make it works.
Below is an example :
If I define hpp like this :
a)
// in hpp file
namespace QuantLib {
class TestSettings
{
public:
void test();
{
Date d = Settings::instance().evaluationDate();
}
};
}
or like this
b)
// in hpp file
namespace QuantLib {
class TestSettings
{
public:
void test();
};
void TestSettings::test()
{
Date d = Settings::instance().evaluationDate();
}
}
everything will work. I do not need to touch singleton.hpp file at all.
But it I have something like this :
// in hpp file
namespace QuantLib {
class TestSettings
{
public:
void test();
};
// in cpp file
namespace QuantLib
{
void TestSettings::test()
{
Date d = Settings::instance().evaluationDate();
}
it will produce exception. The suggestion of Nathan to comment line
#if defined(QL_PATCH_MSVC) && defined(_MANAGED)
and add
#if defined(QL_PATCH_MSVC)
does not help. I still getting the same exception.
Now suppose I do like this:
// in hpp file
namespace QuantLib {
class TestSettings
{
public:
void test();
};
// in cpp file
namespace QuantLib
{
void TestSettings::test()
{
Date d = Date::todaysDate();
}
than no exception. So, I assume it comes from Settings::instance().evaluationDate();
In the same time, debugger does not allow me to step into unmanaged function void TestSettings::test() (it just skipping line)
which is possible in the case when implementation defined in hpp file. It is the same for Date d = Date::todaysDate(); or for
Date d = Settings::instance().evaluationDate();
>Also: what happens if you define an inline function in a hpp file that
>calls Settings::instance().
>evaluationDate(), and then you implement the
>"test" function in a separate cpp and make it call the new function?
// in hpp file
namespace QuantLib {
class TestSettings
{
public:
void test();
};
inline void setDate(const Date& d) { // in hpp file
Settings::instance().evaluationDate() = d;
}
}
// in cpp file
namespace QuantLib
{
void TestSettings::test()
{
Date d = Date::todaysDate();
setDate(d);
}
will produce still the same exception.
Thank you,
Boris.
On Thu, Sep 24, 2009 at 10:00 AM, Luigi Ballabio
<[hidden email]> wrote:
On Tue, 2009-09-22 at 14:25 -0400, Boris Skorodumov wrote:
> This is what I see. As long as in unmanaged code i have implementation
> of function test (which call Settings::instance().evaluationDate())
> inside of the class TestSettings or as inline function in the same hpp
> file - no problems. it works with current singleton.hpp
> implementation. If I have implementation of test in separated cpp file
> then exeption occures. It occurs in either way with commented line 70
> and substituted by #if defined(QL_PATCH_MSVC) or as it is right now
> in singleton.hpp.
Wait, I didn't quite get the last part. With the code as it is now, it
doesn't work in either way. For it to work, you have to comment out the
"inline" on line 70. Is this correct?
Also: what happens if you define an inline function in a hpp file that
calls Settings::instance().evaluationDate(), and then you implement the
"test" function in a separate cpp and make it call the new function?
Something like:
-----
inline void setDate(const Date& d) { // in hpp file
Settings::instance().evaluationDate() = d;
}
-----
void TestSettings::test() // in separate cpp file
{
Date todaysDate = Date::todaysDate();
setDate(todaysDate);
}
--
Olmstead's Law:
After all is said and done, a hell of a lot more is said
than done.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users