Member Avatar

Dear Kind-Coders, I am trying to learn to use boost::shared_ptr to manage the lifetime of a DLL, but I am having a type conversion problem whilst setting it up. Please see the following code: #include <boost/make_shared.hpp> int main() { { class CMyClass { public: CMyClass() {} ~CMyClass() {} int MyInt; }; typedef void* (*fpFunct1)(); fpFunct1 CreateFoo; /*********************************************** Build error because cannot convert from 'HINSTANCE__ *' to 'HINSTANCE__ **' ************************************************/ boost::shared_ptr<HMODULE> spHDL (LoadLibrary("DllMain.dll"), FreeLibrary); // get the function pointer CreateFoo = (fpFunct1)(GetProcAddress(*spHDL, "CreateFooClassInstance")); // get pointer to object auto pMyClass = boost::make_shared<CMyClass*> (static_cast<CMyClass*> (CreateFoo())); (*pMyClass)->MyInt = 9; } // See destructor/custom_deleter …

Member Avatar
+0 forum 5
Member Avatar

Hello all, I have not tested the code I'm posting here to see if it compiles, but I have an issue in a large codebase and I believe that this should be the simplest program to demonstrate the issue; class base { public: shared_ptr<base> clone()=0; }; typedef shared_ptr<base> baseptr; class derived : public base { public: baseptr clone(){ return baseptr(new derived);//the equiv of this compiles in my codebase, //so it should work here } }; typedef shared_ptr<derived> derivedptr; typedef vector<derivedptr> derivedList; int main(){ derivedptr der(new derived);//equivelent comiles derivedList list;//fine list.push_back(der);//works baseptr bas = der->clone();//works derivedptr der2 = der->clone();//compiler error //error …

Member Avatar
+0 forum 15

The End.