Exforsys

Free Training

Class and Pointers

This is a discussion on Class and Pointers within the C and C++ forums, part of the Programming Talk category; I have my class defined as sample. I want to declare a pointer to an int member of class sample ...

Go Back   Exforsys > Programming Talk > C and C++

Exforsys.com


C and C++ C and C++

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 05-17-2007, 05:16 PM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-18-2007, 05:22 AM
Junior Member
 
Join Date: May 2007
Posts: 9
hvg_99 is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-19-2007, 03:24 PM
Senior Member
 
Join Date: Apr 2006
Posts: 162
sammy is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 09:12 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.