I’m using VS2010.
In the constructor of my non-compyable Scene class I have :
auto& character_mgr = CharacterManager::Instance();
character_mgr.initialize();
character_mgr.add_observer( std::bind( &Scene::on_character_event, *this, std::placeholders::_1, std::placeholders::_2 ) );
Here add_observer is defined as :
void add_observer( Observer observer ){ ... }
with Observer defined as :
typedef std::function< void ( CharacterEvent, const Character& ) > Observer;
The problem is that the compiler tells me there is an attempt to copy my Scene, that I provided in the bind using *this, thinking it would keep a reference on it, not trying to copy it when I copy the functor generated by the binding.
- Why does it try to copy my object? Is it normal?
- How should I do to avoid the copy while providing the member function of my object?
1 Answer