|
|||
|
Class and Pointers
I have my class defined as sample. I want to declare a pointer to an int member of class sample and also initialize the pointer to a member. Kindly tell me how I can achieve this. I know concepts of pointers and class separately but want to try out combining both in this example. Kindly help me out.
|
| Sponsored Links |
|
|||
|
Pointers
class sample{
public: int i; } int main(){ // declare a pointer to a data member int sample::*ptr=&sample::i; } Here 'i' is a member of sample class and ptr is a pointer to a member of sample class. I hope i have cleared your doubt, Regards, Gayatri |
|
|||
|
It was a excellent explanation that clarified my doubt about declare a pointer to member of a class and also on initializing the pointer to the member. Kindly tell me whether we can handle pointers concepts in the same way as we handle in C or is there any restriction in C++ or any new feature related to pointer usage in C++ which is not in C.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Solaris x86 FAQ 1/2 | Dan Anderson | Tech FAQ | 2 | 09-23-2008 03:15 AM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 06-18-2004 01:58 PM |
| comp.lang.c Answers to Frequently Asked Questions (FAQ List) | Steve Summit | Tech FAQ | 0 | 06-01-2004 06:00 AM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 05-18-2004 01:59 PM |
| Objective-C FAQ | stes@pandora.be | Tech FAQ | 0 | 04-16-2004 01:51 PM |