+ Reply to Thread
Results 1 to 2 of 2

Thread: Why does pointer to data member function does not work?

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    24

    Why does pointer to data member function does not work?

    I have following example:

    Code:
    class CPointerToMember
    {
    public:
    	int GetrData(int nData)
    	{
    		return nData ;
    	}
    } ;
    
    void UsePointerToMember()
    {
    	CPointerToMember objPointerToMember ;
    
    	int (CPointerToMember::*pfnGetData) (int) = CPointerToMember::GetrData ;
    
    	int nData = objPointerToMember.*pfnGetData(1024) ;
    }
    Compiler throws : "error C2064: term does not evaluate to a function"

    What is the reason?

    Am I missing something?

  2. #2
    It seems that you forgot parenthesis while making a call.

    Following works fine for me:

    Code:
    class CPointerToMember
    {
    public:
    	int GetrData(int nData)
    	{
    		return nData ;
    	}
    } ;
    
    void UsePointerToMember()
    {
    	CPointerToMember objPointerToMember ;
    
    	int (CPointerToMember::*pfnGetData) (int) = CPointerToMember::GetrData ;
    
    	int nData = (objPointerToMember.*pfnGetData)(1024) ;
    }
    Enjoy!

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts