Hi there!
As some of you may know I'm still a beginner with C++, so sometimes I got newbie questions.
Let's suppose, I have this object:
class aClass
{
public:
aClass () { // initialize stuff }
void Update () { // update stuff, not relevant }
void Draw (const sf::RenderTarget& target)
{
Sprite.Draw(target);
}
private:
sf::Sprite Sprite;
};
I have a few of this object in a vector:
std::vector<aClass> vec;
So, I was experimenting with for_each and std::mem_fun_ref, and I came up with this:
// win is a sf::RenderWindow object
for_each(vec.begin(), vec.end(), std::mem_fun_ref(&aClass::Update));
for_each(vec.begin(), vec.end(), std::bind(std::mem_fun_ref(&aClass::Draw), win));
I compile it with -std=c++0x using g++ (4.6, so it supports C++0x), under Linux, and I got a nice error message, "error: use of deleted function" at the second line. After a bit of Google, I really didn't get a good answer. I think, it is because the sf::RenderWindow is a non-copyable class, which is the base class of sf::RenderTarget. Is this correct ? Or I'm doing it in a wrong way ?
Because, if I use a "classic" for loop, it compiles just fine. (note: the first line compiles without any error, and does what it should do in both cases)
std::vector<aClass>::iterator iter;
for (iter = vec.begin(); iter != vec.end(); ++iter)
{
iter->Draw(win);
}