I have the following code trying to use bind1st,
class C1{
...
};
class C2{
...
};
class util{
static bool isSame(C1*, C2*);
};
int main(){
vector<C2*> c2s;
C1* c1;
...
vector<C2*>::it erator itr = find(c2s.begin( ), c2s.end(),
bind1st(mem_fun (util::isSame), c1);
);
But my compiler complains syntax error in calling bind1st, do you see
anything wrong?
Thanks. 3 1768
On Sat, 07 Aug 2004 21:14:11 -0600, John Black <bl***@eed.co m> wrote: I have the following code trying to use bind1st,
class C1{ ... };
class C2{ ... };
class util{ static bool isSame(C1*, C2*); };
int main(){ vector<C2*> c2s; C1* c1;
...
vector<C2*>::it erator itr = find(c2s.begin( ), c2s.end(), bind1st(mem_fun (util::isSame), c1); );
But my compiler complains syntax error in calling bind1st, do you see anything wrong?
Thanks.
Yes lots.
You have a spurious semi colon (or mismatched parens).
You are missing a & before util::isSame.
mem_fun only works on member functions, not static member functions.
mem_fun only works on member functions with zero or one arguments.
There is no version of find that takes a predicate, perhaps you meant
find_if.
The following compiles, is this what you meant?
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
class C2{
};
class C1{
public:
bool isSame(C2*) { return false; }
};
int main(){
vector<C2*> c2s;
C1* c1;
vector<C2*>::it erator itr = find_if(c2s.beg in(), c2s.end(),
bind1st(mem_fun (&C1::isSame) , c1)
);
}
john
John Harrison wrote: On Sat, 07 Aug 2004 21:14:11 -0600, John Black <bl***@eed.co m> wrote:
I have the following code trying to use bind1st,
class C1{ ... };
class C2{ ... };
class util{ static bool isSame(C1*, C2*); };
int main(){ vector<C2*> c2s; C1* c1;
...
vector<C2*>::it erator itr = find(c2s.begin( ), c2s.end(), bind1st(mem_fun (util::isSame), c1); );
But my compiler complains syntax error in calling bind1st, do you see anything wrong?
Thanks.
Yes lots.
You have a spurious semi colon (or mismatched parens).
You are missing a & before util::isSame.
mem_fun only works on member functions, not static member functions.
mem_fun only works on member functions with zero or one arguments.
There is no version of find that takes a predicate, perhaps you meant find_if.
The following compiles, is this what you meant?
#include <vector> #include <functional> #include <algorithm> using namespace std;
class C2{ };
class C1{ public: bool isSame(C2*) { return false; } };
int main(){ vector<C2*> c2s; C1* c1; vector<C2*>::it erator itr = find_if(c2s.beg in(), c2s.end(), bind1st(mem_fun (&C1::isSame) , c1) ); }
john
Thanks for your pointing, actually before your post I found that I should
not use mem_fun because my binary_predicta ble function is static, and in
my code, it must be a static function, so I changed bind1st like this,
vector<C2*>::it erator itr = find_if(c2s.beg in(), c2s.end(),
bind1st(ptr_fun (util::isSame), c1);
Is there any wrong here?
On Sun, 08 Aug 2004 00:12:32 -0600, John Black <bl***@eed.co m> wrote: John Harrison wrote:
Thanks for your pointing, actually before your post I found that I should not use mem_fun because my binary_predicta ble function is static, and in my code, it must be a static function, so I changed bind1st like this,
vector<C2*>::it erator itr = find_if(c2s.beg in(), c2s.end(), bind1st(ptr_fun (util::isSame), c1);
Is there any wrong here?
Apart from the missing ) is looks OK to me.
john This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: wenmang |
last post by:
Hi, all:
I am reading Herb Sutter's article:
http://www.cuj.com/documents/s=8840/cujexp0309sutter/
I have trouble to understand for following lines:
class Subject {
// ...
public:
virtual void Attach( function<void (Subject*)> o ) {
obs_.push_back(o); } --Line1
|
by: Fred Ma |
last post by:
Hello,
I have a random generator that takes a scaling factor as an
argument. Since it takes one argument, it is not a
generator in the sense defined by SGI's online STL
documentation. I'd like to use this as a generator in the
STL algorithm "generate". I know I have to change random
generator from its current implementation to make it
adaptable. But unlike the bind1st adapter, there isn't any
premade function adapter that reduces...
|
by: Greg Lilley |
last post by:
I have an application where I want to remove all of the items that are
in one vector from a second vector. In the following short program, my
objective is to remove all of ourCards from cardsAvailable without
writing a loop.
I have tried a number of different variations using the for_each
algorithm without success, and am currently getting a C2664 error that
the compiler cannot convert parameter 1. I am new to STL and not all
that adept...
|
by: Marc |
last post by:
T x;
T foo(T, T);
bind1st(ptr_fun(foo), x)
creates a function object that takes an argument of type T const&. This
does not work if T is already a reference type like int const&. So my
first problem is with the &. My second problem is with the const. Why
should bind1st change the constness of the second argument of the
function ?
|
by: titan0111 |
last post by:
#include<iostream>
#include<iomanip>
#include<cstring>
#include<fstream>
using namespace std;
class snowfall
{
private:
int ft;
| |
by: Alberto |
last post by:
Hello,
while writing a program I ran across the problem of using for_each.
Although I can traverse lists with a for loop, I'd prefer to use STL's
for_each. Here's my faulty code:
#include <iostream>
#include <list>
#include <algorithm>
|
by: silverburgh.meryl |
last post by:
I am reading an bind1st example from
http://www.roguewave.com/support/docs/sourcepro/stdlibref/bind1st.html
Can someone please tell me why
// Even better, construct the new predicate on the fly.
vector::iterator it2 =
std::find_if (v1.begin (), v1.end (),
std::bind1st (equal_to (), 3));
is better than
|
by: pillbug |
last post by:
I'm having trouble using bind1st with mem_fun1. I can't compile
the line marked below with a @@. If I use the join2 method everything
is fine, but I wind up passing string vectors by value. I would like
to use the reference passing version, or something similar.
The errors I get point the finger at binder1st::operator() being defined
as "const argument_type&" which becomes "const const string_vector&&"
when i use Joiner::join below.
...
|
by: Kenneth Brody |
last post by:
The recent thread on "query about main()" got me thinking...
As I recall, calling a function with the wrong parameters causes
undefined behavior.
(These all assume that no prototype of foo() is in scope.)
For example:
==== fileA.c
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |