472,958 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

why int ** test :: iptr = & test :: i ; is incorrect?

HI,

I have following terrific confusion.

class test
{
public:
int i;
int * j;
int **k;
};

int main()
{

//following is the correct syntax.
int test ::* iptr = & test ::i;
int* test::*iptrptr = & test :: j;
int** test :: * iptrptrptr = & test :: k;
//Ok.But I am tempted to use following syntax.
//int* test :: iptr = & test ::i;
//int** test::iptrptr = & test :: j;
//int*** test :: iptrptrptr = & test :: k;
return 1;
}

so can any one tell me why the following syntax is incorrect
int* test :: iptr = & test ::i;
int** test::iptrptr = & test :: j;
int*** test :: iptrptrptr = & test :: k;

Well, I can use the correct syntax with comfort but somehow I am unable
to convince myself why the incorrect syntax is incorrect.
(The confusion will be over once someone tells me the logical thinking
reason behind this and not the kind of answer that compilers interpret
in that way!!:))

Thanks and Regards,
Yogesh Joshi

Feb 9 '06 #1
6 2560
yp*********@indiatimes.com wrote:
I have following terrific confusion.
[...]
int * test :: blah ;

declares a pointer to an int and gives it the name 'test::blah'. It can
be 'blah' member in the 'test' class. It can be 'blah' object inside the
'test' namespace.

int test :: * blah ;

declares 'blah' variable a pointer to int member of 'test'. These are
just rules of syntax for declaring two different things.
Well, I can use the correct syntax with comfort but [...]


Well, when I am in Japan, I have to drive on the left side of the road.
I can drive on the left side with comfort but somehow I am unable to
convince myself why driving on the right would be incorrect...
Feb 9 '06 #2

Victor Bazarov wrote:
yp*********@indiatimes.com wrote:
I have following terrific confusion.
[...]


int * test :: blah ;

declares a pointer to an int and gives it the name 'test::blah'. It can
be 'blah' member in the 'test' class. It can be 'blah' object inside the
'test' namespace.

int test :: * blah ;

declares 'blah' variable a pointer to int member of 'test'. These are
just rules of syntax for declaring two different things.
Well, I can use the correct syntax with comfort but [...]


Well, when I am in Japan, I have to drive on the left side of the road.
I can drive on the left side with comfort but somehow I am unable to
convince myself why driving on the right would be incorrect...

Gr8 answer..must apprieciate it..

Feb 9 '06 #3
Well, when I am in Japan, I have to drive on the left side of the road.
I can drive on the left side with comfort but somehow I am unable to
convince myself why driving on the right would be incorrect...


good answer..must appricate it..

regards,
Yogesh Joshi

Feb 9 '06 #4
In message <11**********************@g44g2000cwa.googlegroups .com>,
yp*********@indiatimes.com writes
HI,

I have following terrific confusion.

class test
{
public:
int i;
int * j;
int **k;
};

int main()
{

//following is the correct syntax.
int test ::* iptr = & test ::i;
int* test::*iptrptr = & test :: j;
int** test :: * iptrptrptr = & test :: k;
//Ok.But I am tempted to use following syntax.
//int* test :: iptr = & test ::i;
//int** test::iptrptr = & test :: j;
//int*** test :: iptrptrptr = & test :: k;
return 1;
}

so can any one tell me why the following syntax is incorrect
int* test :: iptr = & test ::i;
int** test::iptrptr = & test :: j;
int*** test :: iptrptrptr = & test :: k;

Well, I can use the correct syntax with comfort but somehow I am unable
to convince myself why the incorrect syntax is incorrect.
(The confusion will be over once someone tells me the logical thinking
reason behind this and not the kind of answer that compilers interpret
in that way!!:))


When making sense of a declaration, you have to start from the name and
work outwards, which in this case means right to left. So:
[read the following with fixed-pitch font]

int test :: * iptr means

"iptr" is a
* pointer
:: to member
test of class test
int of type int

"iptr is a pointer-to-member of class test which points to some int
member of the class."

Whereas

int * test :: iptr would mean
"iptr" is a
:: member of
test class test
* pointing to
int an int

IOW, "iptr is a member of class test which points to an int", which
clearly isn't true.

It's doubly confusing here because of course a pointer-to-member isn't
really a pointer. It carries the extra information the compiler needs,
given an object of a class, to locate a particular member within it.

--
Richard Herring
Feb 9 '06 #5
<yp*********@indiatimes.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

Victor Bazarov wrote:

<snip>
Well, when I am in Japan, I have to drive on the left side of the road.
I can drive on the left side with comfort but somehow I am unable to
convince myself why driving on the right would be incorrect...


Curriously enough, I was in Scotland a year and a half (I live in the
states) where they also drive on the left. I thought it only bugged me for
a while. But after I was there more than a year we were taking a long trip
out on some country roads, and the driver thought it would be funny to drive
on the correct side for a change, the right side. The funny thing was, I
actually relaxed when he was driving on the wrong side of the road, because
to me in my brain it was the right side. Then he want back to driving on
the left side and I felt myself tense up...
Feb 9 '06 #6
> int test :: * iptr means

"iptr" is a
* pointer
:: to member
test of class test
int of type int


after few searches on google and peeping through the C++ books, I
recollected that

..* and ->*are pointer to member operator used for dereferencing the
pointer...
so if ::* is also some kind of an operator ( like declaration operator
for pointer to member ) then the ambiguity in logical thinking can be
resolved.
But unfortunately ::* is not defined as any operator....

regards,
Yogesh Joshi

Feb 9 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
27
by: Josh | last post by:
We have a program written in VB6 (over 100,000 lines of code and 230 UI screens) that we want to get out of VB and into a better language. The program is over 10 years old and has already been...
14
by: Arne | last post by:
A lot of Firefox users I know, says they have problems with validation where the ampersand sign has to be written as &amp; to be valid. I don't have Firefox my self and don't wont to install it only...
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
2
by: sani8888 | last post by:
Hi everybody I am a beginner with C++ programming. And I need some help. How can I start with this program *********** The program is using a text file of information as the source of the...
3
lee123
by: lee123 | last post by:
I have a problem getting the correct to count +1 every time I get an answer right and the incorrect is the same. I have two lbl's named number1 and number2 which produces a Rnd# in each lbl. ...
5
by: versesane | last post by:
So I was asked what happens when new is called. I said it acquires memory -calls the constructor -does the typecasting and returns the pointer. If there is no memory available it throws a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.