473,750 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I want to get member function pointer...

class CAnalyzer
{
// attribute
private:
public:
// behavior
private:
void NullFunc(NODE *pNode);
void TraverseNode(NO DE* pNode, void (*preFunc)(NODE *node), void
(*postFunc)(NOD E *node));
public:
void BuildSymbolTbl( NODE *pRootNode);
void CheckType(NODE *pRootNode);
// debug
void PrintNode(NODE *pNode);
};

I defined CAnalyzer class like this...
I want to get PrintNode and NullFunc function pointer and put this to
TraverseNode args...

I just described to get function pointer like this...

void CAnalyzer::Buil dSymbolTbl(NODE *pSyntaxTree)
{
typedef void (CAnalyzer::*pP rintNode)(NODE *pNode);
typedef void (CAnalyzer::*pN ullFunc)(NODE *pNode);
pPrintNode t = &CAnalyzer::Pri ntNode;
pNullFunc t2 = &CAnalyzer::Nul lFunc;
TraverseNode(pS yntaxTree, t, t2);
}

then... when I compile this code, compiler inform me this error msg.

error C2664: 'TraverseNode' : cannot convert parameter 2 from 'void
(__thiscall CAnalyzer::*)(u nion tagNodeType *)' to 'void (__cdecl
*)(union tagNodeType *)'
There is no context in which this conversion is possible

I know that member function in class is type of (__cdecl*)...
and (CAnalzer::*pPr intNode) is __thiscall*...
how can I get the correct member function pointers...
Jul 22 '05 #1
3 3096

"LinusLee" <lo****@hanmail .net> wrote in message
news:6c******** *************** ***@posting.goo gle.com...
class CAnalyzer
{
// attribute
private:
public:
// behavior
private:
void NullFunc(NODE *pNode);
void TraverseNode(NO DE* pNode, void (*preFunc)(NODE *node), void
(*postFunc)(NOD E *node));
public:
void BuildSymbolTbl( NODE *pRootNode);
void CheckType(NODE *pRootNode);
// debug
void PrintNode(NODE *pNode);
};

I defined CAnalyzer class like this...
I want to get PrintNode and NullFunc function pointer and put this to
TraverseNode args...

I just described to get function pointer like this...

void CAnalyzer::Buil dSymbolTbl(NODE *pSyntaxTree)
{
typedef void (CAnalyzer::*pP rintNode)(NODE *pNode);
typedef void (CAnalyzer::*pN ullFunc)(NODE *pNode);
pPrintNode t = &CAnalyzer::Pri ntNode;
pNullFunc t2 = &CAnalyzer::Nul lFunc;
TraverseNode(pS yntaxTree, t, t2);
}

then... when I compile this code, compiler inform me this error msg.

error C2664: 'TraverseNode' : cannot convert parameter 2 from 'void
(__thiscall CAnalyzer::*)(u nion tagNodeType *)' to 'void (__cdecl
*)(union tagNodeType *)'
There is no context in which this conversion is possible

I know that member function in class is type of (__cdecl*)...
and (CAnalzer::*pPr intNode) is __thiscall*...
how can I get the correct member function pointers...


You are trying to convert a member function pointer to an ordinary function
pointer. That is impossible.

If you really want to use member function pointers then you are going to
have to rewrite TraverseNode. If you want to use regular function pointers
then you are going to have to rewrite everything else.

Assuming you want member function pointers then something like this

class CAnalyzer
{
....
typedef void (CAnalyser::* NODE_FUNC)(NODE *);
void TraverseNode(NO DE* pNode, NODE_FUNC preFunc, NODE_FUNC postFunc);
....
};

void CAnalyzer::Buil dSymbolTbl(NODE *pSyntaxTree)
{
TraverseNode(pS yntaxTree, &CAnalyzer::Pri ntNode, &CAnalyzer::Nul lFunc);
}

Can't help you rewrite TraverseNode because you didn't post the code for
that, but the way you call preFunc and postFunc will be different. Like this

(this->*preFunc)(some Node); // call preFunc with someNode

john
Jul 22 '05 #2
lo****@hanmail. net (LinusLee) wrote:
class CAnalyzer
{
// attribute
private:
public:
// behavior
private:
void NullFunc(NODE *pNode);
void TraverseNode(NO DE* pNode, void (*preFunc)(NODE *node), void
(*postFunc)(NO DE *node));
public:
void BuildSymbolTbl( NODE *pRootNode);
void CheckType(NODE *pRootNode);
// debug
void PrintNode(NODE *pNode);
};

I defined CAnalyzer class like this...
I want to get PrintNode and NullFunc function pointer and put this to
TraverseNode args...

I just described to get function pointer like this...

void CAnalyzer::Buil dSymbolTbl(NODE *pSyntaxTree)
{
typedef void (CAnalyzer::*pP rintNode)(NODE *pNode);
typedef void (CAnalyzer::*pN ullFunc)(NODE *pNode);
pPrintNode t = &CAnalyzer::Pri ntNode;
pNullFunc t2 = &CAnalyzer::Nul lFunc;
TraverseNode(pS yntaxTree, t, t2);
}

then... when I compile this code, compiler inform me this error msg.

error C2664: 'TraverseNode' : cannot convert parameter 2 from 'void
(__thiscall CAnalyzer::*)(u nion tagNodeType *)' to 'void (__cdecl
*)(union tagNodeType *)'
There is no context in which this conversion is possible

I know that member function in class is type of (__cdecl*)...
and (CAnalzer::*pPr intNode) is __thiscall*...
how can I get the correct member function pointers...


Try this:

TraverseNode(pS yntaxTree, bind1st(mem_fun (&CAnalyzer::Pr intNode), this),
bind1st(mem_fun (&CAnalyzer::Nu llFunc), this) );

You might have to rewrite TraverseNode as a template:

template < typename T, typename T2 >
void TraverseNode( SyntaxTree*, T, T2 );
Jul 22 '05 #3
I think you could make this a bit simpler by using Functors or
function objects instead of function pointers. I always find the
syntax for declaring function pointers a headache and have to check
it in the book before anything works. You would also
gain some benefit by having a more powerful pre-and post
function capability, since the functor object could contain its
own separate state. Just a quick resume of functors, these
are objects which have an overloaded () opertor, so they can
be called using the same syntax as a function :

Functor foo;

....in you code somewhere...
foo( pNode ); // uses an overloaded operator() to invoke useful function.

Functors are well documented in the STL standard if you would like more
info.

dave
"LinusLee" <lo****@hanmail .net> wrote in message
news:6c******** *************** ***@posting.goo gle.com...
class CAnalyzer
{
// attribute
private:
public:
// behavior
private:
void NullFunc(NODE *pNode);
void TraverseNode(NO DE* pNode, void (*preFunc)(NODE *node), void
(*postFunc)(NOD E *node));
public:
void BuildSymbolTbl( NODE *pRootNode);
void CheckType(NODE *pRootNode);
// debug
void PrintNode(NODE *pNode);
};

I defined CAnalyzer class like this...
I want to get PrintNode and NullFunc function pointer and put this to
TraverseNode args...

I just described to get function pointer like this...

void CAnalyzer::Buil dSymbolTbl(NODE *pSyntaxTree)
{
typedef void (CAnalyzer::*pP rintNode)(NODE *pNode);
typedef void (CAnalyzer::*pN ullFunc)(NODE *pNode);
pPrintNode t = &CAnalyzer::Pri ntNode;
pNullFunc t2 = &CAnalyzer::Nul lFunc;
TraverseNode(pS yntaxTree, t, t2);
}

then... when I compile this code, compiler inform me this error msg.

error C2664: 'TraverseNode' : cannot convert parameter 2 from 'void
(__thiscall CAnalyzer::*)(u nion tagNodeType *)' to 'void (__cdecl
*)(union tagNodeType *)'
There is no context in which this conversion is possible

I know that member function in class is type of (__cdecl*)...
and (CAnalzer::*pPr intNode) is __thiscall*...
how can I get the correct member function pointers...

Jul 22 '05 #4

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

Similar topics

37
5012
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined signature. When developing this lib, I figured that the pointer-to-member-function, although seemingly an attractive solution, does not work well for us.
15
3491
by: Albert | last post by:
Hi, I need to pass a pointer-to-member-function as a parameter to a function which takes pointer-to-function as an argument. Is there any way to do it besides overloading the function? Here is a small program I wrote to check if I could get the address of the function from the member-function-pointer, so that I could pass it to the function as a normal function-pointer.
7
3037
by: jon wayne | last post by:
Hi I'm a little confused here about the lifetime of a static pointer to member function, Say, I declare,define & initialize a static ptr to mem function in the header file of a class(the class is a helper Singleton class, and is created & deleted as and when required) - Where does the static pointer point to when every single instance of the class is deleted. I presume it'll be dangling pointer- as the code seg to which it's
4
1606
by: Agoston Bejo | last post by:
Hi, I would like to do something like this: struct A { int f(float f); }; .... int g(int(*f1)(float)) { return f1(6.5); }
1
2558
by: Assertor | last post by:
Hi All, Except function pointer to a static member funciton of a class (or a function). As the following code, I could pointer a non-static member function of a class. And "Equal" was printed, the pointer has meaning. But how can I use it??
7
1891
by: Bala L | last post by:
I have a class with a private array data member 'm_array'. I have written a public function, called 'fileRead', to read values into the array from a file. I just noticed that I have declared this function to be const. I dont understand how the code compiled and executed without returning an error or a warning. I am assigning values from a file to m_array inside this function. I thought that a member function can be made const only if...
12
540
by: WaterWalk | last post by:
Hello. I am rather confused by the type of a pointer to class data member. Many c++ texts say that pointer to data member has a special syntax. For example the following class: class MyClass { public: int n; }; The pointer to MyClass.n shall be defined like this:
7
3813
by: WaterWalk | last post by:
Hello. I thought I understood member function pointers, but in fact I don't. Consider the following example: class Base { public: virtual ~Base() {} }; class Derived : public Base {
4
4401
by: Immortal_Nephi | last post by:
I had a lot of research to see how function pointer works. Sometimes, programmers choose switch keyword and function in each case block can be called. Sometimes, they choose ordinary function pointer array instead of switch. They believe that ordinary function pointer is much faster than switch. Think of one variable called selectFunction. selectFunction variable can be the range of 0 through 1,000 or more. Load selectFunction...
0
8836
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,...
1
9338
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,...
0
9256
tracyyun
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...
0
8260
agi2029
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...
0
6080
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();...
0
4712
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.