473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 2595
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.