Newsgroup: comp.lang.c++
Subject: Difference between pointer to the no data member and the pointer to the first member
From: somenath <somenathpal@...>
Date: Sun, 30 Jun 2013 09:25:24 -0700 (PDT)
I am trying to understanding the difference between the pointer to the no data member and pointer to the first member of class.
Also I have learned that ?The value returned from taking the member?s address, however, is always bumped up by 1?.
To understand this concept I wrote the following simple program.
#include<iostream>
using namespace std;
class A
{
public:
int data;
int data2;
};
int main(void)
{
A a1;
int A::*first_data_member =&A::data;
int A::*second_data_member =&A::data2;
int A::*no_data_member ;
cout<<"no_data_member = "<<(no_data_member)<<endl;
cout<<"first_data_member = "<<(first_data_member)<<endl;
cout<<"second_data_member = "<<(second_data_member)<<endl;
return 0;
}
The output of the above program is as follows.
=================================================
no_data_member = 1
first_data_member = 1
second_data_member = 1
================================================
I am not able to understand the output of the program.
My expectation is if no_data_member is 1 then first_data_member sould be = no_data_member + 1 and second_data_member should be = first_data_member +1.
Please let me know where I am going wrong?
Subject: Difference between pointer to the no data member and the pointer to the first member
From: somenath <somenathpal@...>
Date: Sun, 30 Jun 2013 09:25:24 -0700 (PDT)
I am trying to understanding the difference between the pointer to the no data member and pointer to the first member of class.
Also I have learned that ?The value returned from taking the member?s address, however, is always bumped up by 1?.
To understand this concept I wrote the following simple program.
#include<iostream>
using namespace std;
class A
{
public:
int data;
int data2;
};
int main(void)
{
A a1;
int A::*first_data_member =&A::data;
int A::*second_data_member =&A::data2;
int A::*no_data_member ;
cout<<"no_data_member = "<<(no_data_member)<<endl;
cout<<"first_data_member = "<<(first_data_member)<<endl;
cout<<"second_data_member = "<<(second_data_member)<<endl;
return 0;
}
The output of the above program is as follows.
=================================================
no_data_member = 1
first_data_member = 1
second_data_member = 1
================================================
I am not able to understand the output of the program.
My expectation is if no_data_member is 1 then first_data_member sould be = no_data_member + 1 and second_data_member should be = first_data_member +1.
Please let me know where I am going wrong?
via Usenet Forums - Usenet Search,Free Usenet - comp.lang.c++ http://www.pocketbinaries.com/usenet-forums/showthread.php?32173-Difference-between-pointer-to-the-no-data-member-and-the-pointer-to-the-first-member&goto=newpost
View all the progranning help forums at:
http://www.pocketbinaries.com/usenet-forums/forumdisplay.php?128-Coding-forums
No comments:
Post a Comment