different pointer types

Discussion in 'C++' started by thomas, Feb 21, 2008.

  1. thomas

    thomas Guest

    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 *"?
     
    thomas, Feb 21, 2008
    #1
    1. Advertising

  2. On Thu, 21 Feb 2008 13:25:34 +0100, thomas <> wrote:

    > 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.
     
    David Côme, Feb 21, 2008
    #2
    1. Advertising

  3. In message <op.t6vjy61crttu86@debian>, David Côme <>
    writes
    >On Thu, 21 Feb 2008 13:25:34 +0100, thomas <> wrote:
    >
    >> 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.


    "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);


    >Could be use only with object of type A.
    > "int *" a classic pointer.


    --
    Richard Herring
     
    Richard Herring, Feb 21, 2008
    #3
  4. thomas

    James Kanze Guest

    On Feb 21, 2:35 pm, Richard Herring <junk@[127.0.0.1]> wrote:
    > In message <op.t6vjy61crttu86@debian>, David Côme
    > <> writes


    > >On Thu, 21 Feb 2008 13:25:34 +0100, thomas <> wrote:


    > >> 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.


    > "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.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Feb 22, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcus Alanen
    Replies:
    1
    Views:
    328
    Alf P. Steinbach
    Sep 7, 2003
  2. Replies:
    10
    Views:
    704
    Chris Torek
    Feb 4, 2005
  3. Replies:
    5
    Views:
    556
    Thomas J. Gritzan
    Oct 6, 2006
  4. Replies:
    11
    Views:
    1,405
    James Kanze
    Jun 7, 2007
  5. __PaTeR
    Replies:
    7
    Views:
    482
    Barry Schwarz
    Jan 1, 2009
Loading...

Share This Page