Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issue on function pointers

Status
Not open for further replies.

bustrus

Programmer
Oct 29, 2009
2
0
0
ES
Hi there,

I'm trying to use a function pointer in a VCL app in Borland C++ Builder 5.0, but it won't work. I already tried it in a Console app, and it runs perfectly, but using it in VCL doesn't (probably the issue is related to static-non static members, but that's just an idea)

Here's what i did..

//in .h of class TfrmplgXMLstuff, 'private' section, the
//following:

void Check(CXml::Iterator& it);
void (*Delegate)(CXml::Iterator& it);

//in constructor of the form class (.cpp), the following:
//(already tried without &, without the class
//reference 'TfrmplgXMLstuff::', and a long etc of variants)

Delegate = &TfrmplgXMLstuff::Check;

//implementing Funct in .cpp
void TfrmplgXMLstuff::Check(CXml::Iterator& it)
{
// function code
}


The issue is that the compiler marks the assignation line in the contructor (Delegate = &TfrmplgXMLstuff::Check;) as error, and specifies:

[C++ Error] DlgplgXMLstuff.cpp(25): E2034 Cannot convert 'void (TfrmplgXMLstuff::*)(CTree<CXml::CXmlNode,const char *>::iterator &)' to 'void (*)(CTree<CXml::CXmlNode,const char *>::iterator &)'.

Since i used the exac same syntax in a console app, and it worked all right, i can't come up with any new idea...

would any one help?

Thx

B
 
Look up Closure in the help index. You cannot assign a function pointer that points to a member function directly to a variable in BCB, but they implemented something called a closure signature that allows you to do so. I just don;t remember all the details.
 
I went through all that before asking in the forum, and didn't work. The only thing they specify is that i should write explicitly in the code the reference to the class (since i'm working with non-static member functions), that is, ClassName::, in the declaration of the function and the function pointer, and later to make the assignation of the pointer into the function. I have also tried that (even though both my function and my function pointer are members of the same class, and i thought it might be redondant semanticly speaking).
If you (or anyone else) come up with any ideas, i'd appreciate it.

thnx & cheers

B.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top