C
Chris Bruyere
Hi All, I just finished reading the FAQ page on fucntion points, for this
ng, and I just wanted to clarify something.
class MessageCenter
{
....
void addMessage(int i, Message* m); //implemented in .cpp file
}
class Person
{
public:
typef void (MessageCenter::*msgFunc)(int i, Message* m)
void setPostOfficePtr(msgFunc mf);
/*
in cpp file:
m_sendMsgToPostOffice = mf;
*/
....
private:
msgFunc m_sendMsgToPostOffice; //a fcn ptr, send a msg to his/her MsgCtr
}
class HumanResources
{
public:
HumanResources(..., MessageCenter* msgCtr);
/*
in cpp file:
m_msgCtr = msgCtr
*/
... newPerson(..);
/*
in cppfile:
Person* temp = new Person();
temp->setPostOfficePtr(MessageCenter::addMessage); <-----this is
what I would like to talk about
*/
....
private:
MessageCenter* m_msgCtr;
}
As it stands right now, it compiles fine, I haven't tested it yet, but it
should work. My question is this: will that function pointing to
MessageCetner::addMessage to the the MessageCenter pointer passed into
HumanResources? I'm curoius because I have not explictly told it to point
to that member function, so if i had multiple instances of MessageCenter
could that function pointer point to any one of them?
What I would really like is to have something like:
Person* temp = new ...
temp->setPostOfficePtr(m_msgCtr->addMessage)
-But this doesn't compile, when i do compile I get this message:
no matching function for call to `Person::setPostOfficePtr(<unknown type>)'
Person/Person.h:278: candidates are:
void Person::setPostOfficePtr(void (MessageCenter::*)(int, Message*))
So why does this happen? I am very curious to know why and of course, to
know how to fix it.
Thanks for you help. I'm sorry if this is confusing or unreadable, i tried
to comply with this ng's rules as best at I can.
Thanks again
Chris
ng, and I just wanted to clarify something.
class MessageCenter
{
....
void addMessage(int i, Message* m); //implemented in .cpp file
}
class Person
{
public:
typef void (MessageCenter::*msgFunc)(int i, Message* m)
void setPostOfficePtr(msgFunc mf);
/*
in cpp file:
m_sendMsgToPostOffice = mf;
*/
....
private:
msgFunc m_sendMsgToPostOffice; //a fcn ptr, send a msg to his/her MsgCtr
}
class HumanResources
{
public:
HumanResources(..., MessageCenter* msgCtr);
/*
in cpp file:
m_msgCtr = msgCtr
*/
... newPerson(..);
/*
in cppfile:
Person* temp = new Person();
temp->setPostOfficePtr(MessageCenter::addMessage); <-----this is
what I would like to talk about
*/
....
private:
MessageCenter* m_msgCtr;
}
As it stands right now, it compiles fine, I haven't tested it yet, but it
should work. My question is this: will that function pointing to
MessageCetner::addMessage to the the MessageCenter pointer passed into
HumanResources? I'm curoius because I have not explictly told it to point
to that member function, so if i had multiple instances of MessageCenter
could that function pointer point to any one of them?
What I would really like is to have something like:
Person* temp = new ...
temp->setPostOfficePtr(m_msgCtr->addMessage)
-But this doesn't compile, when i do compile I get this message:
no matching function for call to `Person::setPostOfficePtr(<unknown type>)'
Person/Person.h:278: candidates are:
void Person::setPostOfficePtr(void (MessageCenter::*)(int, Message*))
So why does this happen? I am very curious to know why and of course, to
know how to fix it.
Thanks for you help. I'm sorry if this is confusing or unreadable, i tried
to comply with this ng's rules as best at I can.
Thanks again
Chris