//the simple code -
template<typename T>
-
class CallBack
-
{
-
public:
-
typedef void (T::*Func)(unsigned short);
-
CallBack(T *t, Func f):_t(t),_f(f)
-
{}
-
void operator()(unsigned short port)
-
{
-
_t->*_f(port);
-
}
-
private:
-
T *_t;
-
Func _f;
-
}
-
//test base class
-
class testBase
-
{
-
public:
-
virtual ~testBase(){};
-
virtual void do(unsigned short port) = 0;
-
};
-
//test class
-
class Test: public testBase
-
{
-
public:
-
void do(unsigned short port)
-
{...}
-
};
-
//
-
// std::list<unsigned short> someList;
-
// std::list<Test*>::iterator it ...
-
//
-
for_each(someList.begin(),someList.end(),CallBack<testBase>(*it,&testBase::do));
-
// has an error
-
// C2064: term does not evaluate to a function taking 1 arguments with VS2005
-
does anyone know how to do this? thanks!
7 1507 JosAH 11,448
Recognized Expert MVP
You cannot name a function 'do', i.e. it's a reserved word.
kind regards,
Jos
You cannot name a function 'do', i.e. it's a reserved word.
kind regards,
Jos
sorry just a mistake, I mean just a Function Name here's code: -
template<typename T>
-
class CallBack
-
{
-
public:
-
typedef void (T::*Func)(unsigned short);
-
CallBack(T *t, Func f):_t(t),_f(f)
-
{}
-
void operator()(unsigned short port)
-
{
-
_t->*_f(port);
-
}
-
private:
-
T *_t;
-
Func _f;
-
}
-
//test base class
-
class testBase
-
{
-
public:
-
virtual ~testBase(){};
-
virtual void doSomething(unsigned short port) = 0;
-
};
-
//test class
-
class Test: public testBase
-
{
-
public:
-
void doSomething(unsigned short port)
-
{...}
-
};
-
//
-
// std::list<unsigned short> someList;
-
// std::list<Test*>::iterator it ...
-
//
-
for_each(someList.begin(),someList.end(),CallBack<testBase>(*it,&testBase::doSomething));
-
// has an error
-
// C2064: term does not evaluate to a function taking 1 arguments with VS2005
-
how to do it ? thanks
JosAH 11,448
Recognized Expert MVP
sorry just a mistake, I mean just a Function Name here's code: -
template<typename T>
-
class CallBack
-
{
-
public:
-
typedef void (T::*Func)(unsigned short);
-
CallBack(T *t, Func f):_t(t),_f(f)
-
{}
-
void operator()(unsigned short port)
-
{
-
_t->*_f(port);
-
}
-
private:
-
T *_t;
-
Func _f;
-
}
-
//test base class
-
class testBase
-
{
-
public:
-
virtual ~testBase(){};
-
virtual void doSomething(unsigned short port) = 0;
-
};
-
//test class
-
class Test: public testBase
-
{
-
public:
-
void doSomething(unsigned short port)
-
{...}
-
};
-
//
-
// std::list<unsigned short> someList;
-
// std::list<Test*>::iterator it ...
-
//
-
for_each(someList.begin(),someList.end(),CallBack<testBase>(*it,&testBase::doSomething));
-
// has an error
-
// C2064: term does not evaluate to a function taking 1 arguments with VS2005
-
how to do it ? thanks
The first parameter of your CallBack constructor call isn't correct; change the
for_each line to two lines: -
TestBase tb;
-
for_each(someList.begin(),someList.end(),CallBack<testBase>(&tb ,&testBase::doSomething));
kind regards,
Jos
The first parameter of your CallBack constructor call isn't correct; change the
for_each line to two lines: -
TestBase tb;
-
for_each(someList.begin(),someList.end(),CallBack<testBase>(&tb ,&testBase::doSomething));
kind regards,
Jos
(*it) means a pointer to a Test*
such as: -
std::list<testBase*> testList;
-
testList.push_back(new Test());
-
std::list<unsigned short>::iterator it = testList.begin();
-
//that should be correct,OK?
-
for_each(someList.begin(),someList.end(),CallBack<testBase>((*it) ,&testBase::doSomething))
-
Thanks
JosAH 11,448
Recognized Expert MVP
(*it) means a pointer to a Test*
such as: -
std::list<testBase*> testList;
-
testList.push_back(new Test());
-
std::list<unsigned short>::iterator it = testList.begin();
-
//that should be correct,OK?
-
for_each(someList.begin(),someList.end(),CallBack<testBase>((*it) ,&testBase::doSomething))
-
Thanks
No, now your iterator 'it' is an iterator over a list of unsigned shorts. I played a
bit with your code (and changed some names on the fly). This is what I got
(it works): -
// in my .h file:
-
template<class T>
-
class CallBack
-
{
-
public:
-
typedef void (T::*func_t)(int);
-
-
CallBack(T* t, func_t f):_t(t),_f(f) {}
-
void operator()(int p) {
-
(_t->*_f)(p);
-
}
-
-
private:
-
T*_t;
-
func_t _f;
-
};
-
-
class DoFunc {
-
public:
-
virtual void func(int i) { std::cout << i << std::endl; }
-
};
I tested that bit with this: -
// in my .cpp file:
-
vector<int> v;
-
-
for (int j= 0; j < 10; j++)
-
v.push_back(j);
-
-
vector<DoFunc*> df;
-
-
df.push_back(new DoFunc());
-
vector<DoFunc*>::iterator it= df.begin();
-
-
for_each(v.begin(),v.end(),CallBack<DoFunc>(*it, &DoFunc::func));
kind regards,
Jos
god save me , how many mistake i have made;
in fact all i want to write is std::list<testBase*>::iterator it = testList.begin(),
but I …
sorry for my baby mistakes;
(_t->*_f)(p); //-----------------------I missed the brackets
Now it works fine , Thank you very much ,Jos.
JosAH 11,448
Recognized Expert MVP
(_t->*_f)(p); //-----------------------I missed the brackets
Now it works fine , Thank you very much ,Jos.
Oh dear, I missed it completely that your code didn't have the parentheses;
I just assumed you typed the same stuff as I did when I tested your idea ...
Well, we solved the problem by sheer serendipity then ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Andrew |
last post by:
I tried the following session example
/**************The first page - page1.php *******************/
<?php
// page1.php
session_start();
echo 'Welcome to page #1';
|
by: Rene Olsthoorn |
last post by:
Dear readers,
py2exe has a problem including libxml2. Not at building time, but at
runtime. The libxml2.dll cannot be loaded... Is there anyone that NOT has
the problem? (and can you drop me your setup.py scipt, please).
Thanks in advance,
Rene O.
|
by: The Pistoleer |
last post by:
I have an inconsistent problem with some Internet pages when using Netscape
(7.1) that I cannot reproduce with IE nor locally. Below is an example
link.
There are several tables on the pages. The tables at the top containing
small images are working correctly. The tables below that contain product
descriptions and input to purchase an...
|
by: Bob |
last post by:
I cut and pasted the following from the HELP into the form load event of a
new form and I get an error stating that MonthName is a namespace and can not
be used as shown. What's wrong?
Dim MyMonth As Integer
Dim Name As String
MyMonth = 4
Name = MonthName(MyMonth, True) ' "True" returns an abbreviated name.
MsgBox(Name) ' Name...
|
by: Alex |
last post by:
Example uploaded to:
http://www.clickatus.com/ajax/
BTW - This is for FIREFOX, won't work in IE.
I don't know why but when it is executed the browser still in loading
state... Even though XMLHttpRequest already got its string from the
server...
Any help?
| |
by: r2destini |
last post by:
Hi Friends,
I am new to .Net. So I don't know much.
I am facing a problem in updating database through ADO.Net
I am creating the dataset and there is no problem in the updation and
deletion or insertion in the dataset but when I am updating the
database through adaptor error occures (Coloured Red).
|
by: optimistx |
last post by:
Which url in your opinion would be a good or even the best example of
javascript usage in a set of pages at least say 10 or more pages? How to use
css, how to split js-code to files, how to code for good
maintainability,objects, names, how to take care of older browsers, how to
optimize the coding time, etc
It might be easy to have strong...
|
by: Bruce W. Darby |
last post by:
This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could point
me in the right direction.
The history:
My work involves creating custom packages of our software product for golf
courses that purchase our software. The course data is kept as a back up in...
|
by: SQACPP |
last post by:
Hi,
I try to figure out how to use Callback procedure in a C++ form
project
The following code *work* perfectly on a console project
#include "Windows.h"
BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam)
{
|
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...
|
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...
| |
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...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |