Application's pointer

D

davidzada

Hi guys !

I try to work with application's pointers in c++ , and .. I have some
problems !

I have base class that contain definition of pointer to application.
This application's pointer assigned as argument to another application
that exist in this class.
The definition of the base class look like this:

class Base{

//DB
protected:
typedef int (CTMonitorBase::*pFoo) ();

//api
protected:
void Run(pFoo _apFoo);

};


This base class derived to another class. This class contain
application which suitable to the definition of the application's
pointers.
The definition of the class look like this:

class Inheritor : public Base{

int y1;
int z1;

public:
bool UserFunc(); //another new application.
int zoo(); //suitable to the definition of pFoo pointer.

};


When i try to invoke from UserFunc application to Run application with
the pointer of zoo application

bool Inheritor::UserFunc()
{
Run(zoo);
}

I got the following error:

error C2664: 'void __thiscall Base::Run(int (__thiscall Base::*)(void)'
: cannot convert parameter 1 from
'int (void)' to 'int (__thiscall Base::*)(void)'
None of the functions with this name in scope match the target
type


As i understand the problem is, the Run application can't get the
application's pointer of the Inheritor class, without
casting.

Now, I cast the pointer like this:

bool Inheritor::UserFunc()
{
Run(static_cast<pFoo>zoo);
}


But....

When i try to access in the zoo application to the Inheritor database
(like y1,z1), i read and set to wrong address in the memory.
It seems that the Inheritor class lost its database pointer in the zoo
application.

Any ideas or notes are welcome !
 
M

mlimber

I try to work with application's pointers in c++ , and .. I have some
problems !

I have base class that contain definition of pointer to application.
This application's pointer assigned as argument to another application
that exist in this class.
The definition of the base class look like this:

class Base{

//DB
protected:
typedef int (CTMonitorBase::*pFoo) ();

//api
protected:
void Run(pFoo _apFoo);

};


This base class derived to another class. This class contain
application which suitable to the definition of the application's
pointers.
The definition of the class look like this:

class Inheritor : public Base{

int y1;
int z1;

public:
bool UserFunc(); //another new application.
int zoo(); //suitable to the definition of pFoo pointer.

};


When i try to invoke from UserFunc application to Run application with
the pointer of zoo application

bool Inheritor::UserFunc()
{
Run(zoo);
}

I got the following error:

error C2664: 'void __thiscall Base::Run(int (__thiscall Base::*)(void)'
: cannot convert parameter 1 from
'int (void)' to 'int (__thiscall Base::*)(void)'
None of the functions with this name in scope match the target
type


As i understand the problem is, the Run application can't get the
application's pointer of the Inheritor class, without
casting.

Now, I cast the pointer like this:

bool Inheritor::UserFunc()
{
Run(static_cast<pFoo>zoo);
}


But....

When i try to access in the zoo application to the Inheritor database
(like y1,z1), i read and set to wrong address in the memory.
It seems that the Inheritor class lost its database pointer in the zoo
application.

Any ideas or notes are welcome !

Your message is too confusing. Show us a complete but minimal sample
that demonstrates the problem (i.e., one that we can copy and paste
unchanged to get the same error). See this FAQ on posting code:

http://parashift.com/c++-faq-lite/how-to-post.html#faq-5.8

Cheers! --M
 
M

Marcus Kwok

Hi guys !

I try to work with application's pointers in c++ , and .. I have some
problems !

After reading your message, I think everywhere you used "application", I
think you mean "function". Your message becomes much more clear then.
class Base{

//DB
protected:
typedef int (CTMonitorBase::*pFoo) ();

//api
protected:
void Run(pFoo _apFoo);

};


class Inheritor : public Base{

int y1;
int z1;

public:
bool UserFunc(); //another new application.
int zoo(); //suitable to the definition of pFoo pointer.

};


When i try to invoke from UserFunc application to Run application with
the pointer of zoo application

bool Inheritor::UserFunc()
{
Run(zoo);
}

I got the following error:

error C2664: 'void __thiscall Base::Run(int (__thiscall Base::*)(void)'
: cannot convert parameter 1 from
'int (void)' to 'int (__thiscall Base::*)(void)'
None of the functions with this name in scope match the target
type

Maybe try this:

Run(&Inheritor::zoo);

but I am not sure if a pointer to member of derived (Inheritor::*) can
be converted to a pointer to member of base (Base::*).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top