473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How to bind class static member function?

i use a class static member function to for_each:
class t1
{
static test(string s);
}

main()
{
list<string> slist;
...
for_each(slist.begin(), slist.end(), t1::test);
}
this can run, but when i give t1::test a parameter,like this :
class t1
{
static test2(string s, int 5);
}
main()
{
for_each(slist.begin(), slist.end(), bind2nd(t1::test2,5) ); //error !!!
for_each(slist.begin(), slist.end(), bind2nd(ptr_fun(t1::test2,5) ) );
//also error !!!
}

how to resolve this problem?

Jul 23 '05 #1
1 7466
flyaflya wrote:
i use a class static member function to for_each:
class t1
{
static test(string s);
}

main()
{
list<string> slist;
...
for_each(slist.begin(), slist.end(), t1::test);
}
this can run, but when i give t1::test a parameter,like this :
class t1
{
static test2(string s, int 5);
}
main()
{
for_each(slist.begin(), slist.end(), bind2nd(t1::test2,5) );
//error !!! for_each(slist.begin(), slist.end(),
bind2nd(ptr_fun(t1::test2,5) ) ); //also error !!!
The closing parenthesis is in the wrong place.
}

how to resolve this problem?


Use 'bind2nd(ptr_fun(t1::test2),5)' as the third argument to 'for_each'.
-----------------------------
struct A {
static void foo(double,int);
};

#include <list>
#include <functional>
#include <algorithm>
#include <utility>

int main() {
std::list<double> d;
std::for_each(d.begin(), d.end(),
std::bind2nd(std::ptr_fun(A::foo), 5));
}
------------------------------
V
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
8
by: BekTek | last post by:
I have class that has member function that take two argument.. I'd like to use the member function to algorithm such as remove_if.. How can I bind that? class Foo{ void f(){ int a = 10;...
6
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
0
by: flyaflya | last post by:
i use a class static member function to for_each: class t1 { static test(string s); } main() { list<string> slist; ...
9
by: baumann | last post by:
hi all, to implement a singleton class, one has define a static function in the singleton class, class A{ public: static A* getInstance() { static A a; return &a;
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
2
by: IndyStef | last post by:
I am trying to use boost's bind on a member function, on the VC8 compiler. After using several different attempts, I could not get it to work. Does anybody know what is wrong with the code below?...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
6
by: Toby Bradshaw | last post by:
Hi, Consider the following: class A { public: virtual bool foo() = 0; };
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.