different pointer types

T

thomas

can anyone tell me the difference between "int class::*" and "int *"

for example:
class A{
private:
int a;
};

what's the difference between "int A::*" and "int *"?
 
D

David Côme

can anyone tell me the difference between "int class::*" and "int *"

for example:
class A{
private:
int a;
};

what's the difference between "int A::*" and "int *"?


"int A::*" a pointer to a member of A.Could be use only with object of
type A.
"int *" a classic pointer.
 
R

Richard Herring

David Côme <[email protected]> said:
"int A::*" a pointer to a member of A.

"Pointer to member" is a misleading name, since it's not really a
pointer in the usual sense at all, more like an offset (but particularly
if virtual inheritance is involved, it's not as simple as that.) It's
the extra piece of information needed to get from a particular instance
of A to the "pointed-to" member of that instance.

struct A {
int a;
};

int A::*p = &A::a;
A x;
x.*p = 99;
assert (x.a==99);
A * q = &x;
q->*p = 88;
assert(x.a==88);
 
J

James Kanze

In message <op.t6vjy61crttu86@debian>, David Côme
"Pointer to member" is a misleading name, since it's not
really a pointer in the usual sense at all, more like an
offset (but particularly if virtual inheritance is involved,
it's not as simple as that.)

In the case of pointers to member functions, its' even more
complicated.

I agree that another name ("selector", maybe) might be more
appropriate, but it does share at least one thing with standard
pointers: a null pointer constant will convert implicitly to it,
and the result of that conversion is guaranteed to compare
unequal to any valid pointer to member.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top