Note that there are some explanatory texts on larger screens.

plurals
  1. POSyntax for std::binary_function usage
    primarykey
    data
    text
    <p>I'm a newbie at using the STL Algorithms and am currently stuck on a syntax error. My overall goal of this is to filter the source list like you would using Linq in c#. There may be other ways to do this in C++, but I need to understand how to use algorithms.</p> <p>My user-defined function object to use as my function adapter is </p> <pre><code>struct is_Selected_Source : public std::binary_function&lt;SOURCE_DATA *, SOURCE_TYPE, bool&gt; { bool operator()(SOURCE_DATA * test, SOURCE_TYPE ref)const { if (ref == SOURCE_All) return true; return test-&gt;Value == ref; } }; </code></pre> <p>And in my main program, I'm using as follows -</p> <pre><code>typedef std::list&lt;SOURCE_DATA *&gt; LIST; LIST; *localList = new LIST;; LIST* msg = GLOBAL_DATA-&gt;MessageList; SOURCE_TYPE _filter_Msgs_Source = SOURCE_TYPE::SOURCE_All; std::remove_copy(msg-&gt;begin(), msg-&gt;end(), localList-&gt;begin(), std::bind1st(is_Selected_Source&lt;SOURCE_DATA*, SOURCE_TYPE&gt;(), _filter_Msgs_Source)); </code></pre> <p>What I'm getting the following error in Rad Studio 2010. The error means "Your source file used a typedef symbol where a variable should appear in an expression. "</p> <blockquote> <p>"E2108 Improper use of typedef 'is_Selected_Source'"</p> </blockquote> <hr> <p>Edit - After doing more experimentation in VS2010, which has better compiler diagnostics, I found the problem is that the definition of remove_copy only allows uniary functions. I change the function to uniary and got it to work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload