| | |
what's the difference between using an ordinary pointer and a "pointer to member"?
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 16
Reputation:
Solved Threads: 0
what's the difference between using an ordinary pointer and a "pointer to member"?
0
#1 Nov 23rd, 2008
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; #define PRINT(x) cout << #x " = " << x << endl; class Object{ public: Object():i(5){} int i;; }; int main() { Object o; o.i = 5; int* p = &(o.i); PRINT(*p); int Object::* p2m = &Object::i; PRINT(o.*p2m); return 0; }
the two PRINT macros produce this:
C++ Syntax (Toggle Plain Text)
*p = 5 o.*p2m = 5
could you tell me what the difference is between using them? when should i choose one over another? and why?
Thank you in advance!
Last edited by Ancient Dragon; Nov 23rd, 2008 at 10:16 pm. Reason: replaced quote tags with code tags
A little progress a day is what life has to be about.
Re: what's the difference between using an ordinary pointer and a "pointer to member"?
0
#2 Nov 24th, 2008
Re: what's the difference between using an ordinary pointer and a "pointer to member"?
0
#3 Nov 24th, 2008
Read about:
- pointers to member functions:
http://www.gidforums.com/t-18332.html
- pointer to data members:
http://www.icce.rug.nl/documents/cpl...us15.html#l219
- pointers to member functions:
http://www.gidforums.com/t-18332.html
- pointer to data members:
http://www.icce.rug.nl/documents/cpl...us15.html#l219
![]() |
Other Threads in the C++ Forum
- Previous Thread: enum errors help
- Next Thread: Simple C++ Class problem
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






