|
Boost Users : |
Subject: [Boost-users] boost::noncopyable doesn't work
From: Maurer Philipp (philipp.maurer_at_[hidden])
Date: 2008-10-13 08:34:38
Hello,
I have a very special problem concerning boost::noncopyable under
Windows in a shared library. A class deriving from boost::noncopyable
becomes copyable. Strange ? Here is the example code. (Using Visual
Studio 2005, no sp, Windows XP):
1) create one static lib with only TestClasses.hpp with the
following content in it:
#include <boost/noncopyable.hpp>
class INonCopyNormalClass: boost::noncopyable
{
public:
virtual INonCopyNormalClass* clone() = 0;
};
2) create one DLL (shared lib) with the following content:
DLLMain.hpp:
#include "../TestLib/TestClasses.hpp"
# if defined(UNCOPYABLETESTDLL_EXPORTS)
# define DLL_API __declspec(dllexport)
# else
# define DLL_API
# endif
class DLL_API AnotherNonNormalCopyClass: public INonCopyNormalClass
{
};
class YetAnotherNonNormalCopyClass: public AnotherNonNormalCopyClass
{
public:
YetAnotherNonNormalCopyClass();
virtual INonCopyNormalClass* clone();
};
DLLMain.cpp:
#include "DLLmain.hpp"
YetAnotherNonNormalCopyClass::YetAnotherNonNormalCopyClass()
{
}
INonCopyNormalClass* YetAnotherNonNormalCopyClass::clone()
{
return new YetAnotherNonNormalCopyClass(*this);
}
It is quite important that the DLL_API is defined properly !! This seems
to be the reason, that the code above compile, links and runs. This
should not be possible. The line return new
YetAnotherNonNormalCopyClass(*this); should not work. If DLL_API is
undefined or removed, you will get the correct error message and
compilation fails
ANY ideas ? SOMEONE ?
Thanks and best,
Philipp
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net