#include <memory> #include <deque> void MyFunc { std::deque< std::shared_ptr< Sprite* > > SpriteList; func_to_fill_deque( SpriteList ); for( auto i = SpriteList.begin(), end = SpriteList.end(); i != end; i++ ) { SpriteList[ i ]->spriteFunc(); // doesn't work SpriteList.at( i )->spriteFunc(); // also doesn't work } } void func_to_fill_deque( std::deque< std::shared_ptr< Sprite* > >& list ) { ptr = new Sprite( filename ); list.push_back( std::make_shared< Sprite* >( ptr ) ); } When I try SpriteList[ i ] I get a red squiggle under the first '[' with the msg "No operator matches these operands" Trying SpriteList.at( i ) gives a red squiggle …

Member Avatar
Member Avatar
+0 forum 2

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
Member Avatar
+0 forum 5

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
Member Avatar
+0 forum 15

I need helping trying to retrieve data held in a [CODE]std::list<boost::shared_ptr<boost::any>>[/CODE] I am working on a Singleton Controller class with a private [B]std::list[/B]. Client class(es) will be able to [B]Add/Remove/Edit[/B] concrete class objects to be used by the program through this Controller class. The reason for using [B]boost::shared_ptr[/B] is because I assign a unique objID to each concrete class created. Once instance objs are added to controller, user will be able to search and remove objs later. The [B]Add(....)[/B] and [B]Remove(...)[/B] overloaded methods for each concrete class work fine. I am now trying to create [B]getObject(int index)[/B] and [B]setObject(int index)[/B] …

Member Avatar
Member Avatar
+0 forum 2

Hi Daniweb, I've been programming a base class resource manager for a game I'm working on, and so read up on boost's shared_ptr and weak_ptr. I'm done with it and it works and I would really appreciate some feedback on my choice of implementation and design. Am I using the smart pointers in a correct way? Am I overcomplicating things? etc... Here's the code: [CODE] #ifndef RESOURCE_MANAGER_HPP #define RESOURCE_MANAGER_HPP #include <map> #include <string> #include <iostream> #include <stdexcept> #include <boost/smart_ptr/shared_ptr.hpp> #include <boost/smart_ptr/weak_ptr.hpp> template<typename T> class ResourceManager { // Type definitions protected: typedef boost::shared_ptr<T> Resource; // Not to be used by users …

Member Avatar
+0 forum 0

The End.