[Q] scoped_ptr for forward declared classes
Hello I have a situation where I have struct cmoney_impl_dtl; //hidden impl is in Cpp file struct myclass { boost::scoped_ptr<hidden_impl> myimpl_ptr; } The compiler complains that the struct hidden_impl must be fully defined in the header file (which I cannot do) ------------- c:\usr\local\boost.msvc2008\boost_1_38_0\boost\checked_delete.hpp(32) : error C2027: use of undefined type 'cmoney_impl_dtl' c:\dbt_money.hpp(38) : see declaration of 'cmoney_impl_dtl' c:\usr\local\boost.msvc2008\boost_1_38_0\boost\scoped_ptr.hpp(80) : see reference to function template instantiation 'void boost::checked_delete<T>(T *)' being compiled ------------- is there a way around this? I was trying to use shared_ptr there, but MSVC reports memory leak on those objects... so I must be doing something wrong there , and therefore just wanted to try a simple ptr. thanks in advance, Vlad -- V S P toreason@fastmail.fm -- http://www.fastmail.fm - Same, same, but different...
V S P:
Hello
I have a situation where I have
struct cmoney_impl_dtl; //hidden impl is in Cpp file struct myclass {
boost::scoped_ptr<hidden_impl> myimpl_ptr;
}
You must declare ~myclass in the header and implement it in the .cpp file. If your class didn't have a destructor you'd need myclass::~myclass() {} Otherwise, just move the implementation of ~myclass into the .cpp file.
Hello, thank you I tried that, but it does not work I think the scoped_ptr needs the destructor implementation of my hidden impl but that I cannot provide (because I use header files from a library that I cannot expose). I for now switched to just regular ptr and still trying to debug why shared_ptr reports mem leaks with Visual Studio. thank you again, Vlad On Tue, 31 Mar 2009 19:38 +0300, "Peter Dimov" <pdimov@pdimov.com> wrote:
V S P:
Hello
I have a situation where I have
struct cmoney_impl_dtl; //hidden impl is in Cpp file struct myclass {
boost::scoped_ptr<hidden_impl> myimpl_ptr;
}
You must declare ~myclass in the header and implement it in the .cpp file. If your class didn't have a destructor you'd need
myclass::~myclass() {}
Otherwise, just move the implementation of ~myclass into the .cpp file.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - Send your email first class
V S P:
and still trying to debug why shared_ptr reports mem leaks with Visual Studio.
In general, for us to be able to help, you have to post a complete program that reports a leak. Your previous example was not just heavily abbreviated and used the wrong class names, it also didn't have any uses of shared_ptr at all (although it did have a thread_specific_ptr.) False leak reports are typically caused by static variables whose destructors haven't yet run when the leak report is generated. Try calling .reset() on all static shared_ptr variables before exit and see if the leaks disappear.
thank you very much, I do have quite a few static variables. I will try this if does not work, I will create an example of the problem and post it here. I actually started using _CrtMemState state; _CrtMemCheckpoint(&state2); //my heap allocation code goes here _CrtMemDumpAllObjectsSince(&state); and I am seeing much fewer, so I think it coincides with your suggestion about static initializations. Vlad I was just looking for 'look here or try there' type of suggestion which you provided. thanks again, Vlad On Tue, 31 Mar 2009 20:33 +0300, "Peter Dimov" <pdimov@pdimov.com> wrote:
V S P:
and still trying to debug why shared_ptr reports mem leaks with Visual Studio.
In general, for us to be able to help, you have to post a complete program that reports a leak. Your previous example was not just heavily abbreviated and used the wrong class names, it also didn't have any uses of shared_ptr at all (although it did have a thread_specific_ptr.)
False leak reports are typically caused by static variables whose destructors haven't yet run when the leak report is generated. Try calling .reset() on all static shared_ptr variables before exit and see if the leaks disappear.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users -- V S P toreason@fastmail.fm
-- http://www.fastmail.fm - Does exactly what it says on the tin
participants (2)
-
Peter Dimov
-
V S P