943,747 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 582
  • C++ RSS
Aug 26th, 2009
0

Why Can`t member function be called by pointer object of class/struct

Expand Post »
Why Can`t member function be called by pointer object of class/struct.

i was trying to call the member fuction of struct though pointer object it showed me error like

request for member 'Table::reveal' in `T1`, which is of non-class type 'Table*'

where,
Table is structure
reveal is member function
T1 is the object pointer object created though
C++ Syntax (Toggle Plain Text)
  1. typedef Table *Tptr;
  2. Tptr T1;
if yes please help me out
Similar Threads
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
Rhohitman is offline Offline
81 posts
since Dec 2007
Aug 26th, 2009
0

Re: Why Can`t member function be called by pointer object of class/struct

Member access through pointers is different. If you try to do something like T1.reveal() , you would get that error because the dot operator does not work with pointers. You need to dereference the pointer first, then do the access:
C++ Syntax (Toggle Plain Text)
  1. (*T1).reveal();
Because it is such a common operation, there is a special operator to make the whole thing simpler:
C++ Syntax (Toggle Plain Text)
  1. T1->reveal();
Reputation Points: 1446
Solved Threads: 135
Practically a Master Poster
Tom Gunn is offline Offline
681 posts
since Jun 2009
Aug 26th, 2009
0

Re: Why Can`t member function be called by pointer object of class/struct

thank a lot.. i had never done this with the function..........................
Reputation Points: 10
Solved Threads: 5
Junior Poster in Training
Rhohitman is offline Offline
81 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Screen Capture
Next Thread in C++ Forum Timeline: Get node number XX in BST





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC