
- Forum
- Programming Talk
- C and C++
- Class and Pointers
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 ...
-
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.
-
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.
-
Sponsored Ads

Reply With Quote





