Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
observer pattern error (is not captured)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chris Forone  
View profile  
 More options Nov 12 2012, 6:08 am
Newsgroups: comp.lang.c++
From: Chris Forone <4...@gmx.at>
Date: Mon, 12 Nov 2012 12:06:21 +0100
Local: Mon, Nov 12 2012 6:06 am
Subject: observer pattern error (is not captured)
hello group,

in my subject-methode detach(const observer& o) i used following line to
remove the observer:

observers.remove_if([](MyObserver mo){ return &o == &mo; });

gcc 4.7 (mingw) give me the error: 'mo' is not captured. what does this
mean and how can i achieve the desired behavior?

thanks a lot, cheers chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SG  
View profile  
 More options Nov 12 2012, 6:57 am
Newsgroups: comp.lang.c++
From: SG <sgesem...@gmail.invalid>
Date: Mon, 12 Nov 2012 12:57:03 +0100
Local: Mon, Nov 12 2012 6:57 am
Subject: Re: observer pattern error (is not captured)
Am 12.11.2012 12:06, schrieb Chris Forone:

> in my subject-methode detach(const observer& o) i used following line to
> remove the observer:

> observers.remove_if([](MyObserver mo){ return &o == &mo; });

> gcc 4.7 (mingw) give me the error: 'mo' is not captured. what does this
> mean and how can i achieve the desired behavior?

Please post real code the next time.

First of all, the function parameter is passed by value which is
probably NOT what you want. Secondly, I believe that you named your
function parameter "o" instead of "mo". Then, the error messages
actually makes sense because the observer you want to delete is not
known to the lambda because you havn't captured this information.

I am GUESSING (because you did not post the relevant information) that
you should have written

  observers.remove_if([&mo](MyObserver const& o){return &o == &mo;});

I'm guessing observers is some kind of list and somehow you got hold of
reference (mo) to the list element you want to remove. How about
changing this to an iterator instead? Then, you could just remove it
like this:

  list<MyObserver>::iterator mo_iter = ...;
  :::
  observers.erase(mo_iter);

and get rid of the linear search (remove_if).

Cheers!
SG


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Forone  
View profile  
 More options Nov 12 2012, 8:18 am
Newsgroups: comp.lang.c++
From: Chris Forone <4...@gmx.at>
Date: Mon, 12 Nov 2012 14:17:13 +0100
Local: Mon, Nov 12 2012 8:17 am
Subject: Re: observer pattern error (is not captured)
Am 12.11.2012 12:57, schrieb SG:

ah, so its a kind of visibility/scope problem. the var in the square
bracket is local to the lambda?

thanks a lot, cheers, chris


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »