Indirection operator and write access

Discussion in 'C++' started by Paradigm, Jun 2, 2012.

  1. Paradigm

    Paradigm Guest

    Hi

    Here is the scenario:

    There is a pointer variable 'x'.

    For what type of 'x' would the following show a write access on 'x'

    std::cout<<*x<<'\n'; //showing write access on x [what's its type?]

    I could not think of any possible situation apart from overloaded '*' operator having write operation inside the definition itself.

    Hope my question is clear.
    Thanks
     
    Paradigm, Jun 2, 2012
    #1
    1. Advertising

  2. On 6/2/2012 1:22 PM, Paradigm wrote:
    > Here is the scenario:
    >
    > There is a pointer variable 'x'.
    >
    > For what type of 'x' would the following show a write access on 'x'
    >
    > std::cout<<*x<<'\n'; //showing write access on x [what's its type?]
    >
    > I could not think of any possible situation apart from overloaded '*'
    > operator having write operation inside the definition itself.


    You can't overload the operator* for pointers. That's a built-in one.
    Once you dereference *x, you get a reference to the object. The pointer
    variable does not have any play in dealing with that, so it seems that
    the write access to 'x' itself has nothing to do with '*x'.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jun 3, 2012
    #2
    1. Advertising

  3. Paradigm <> writes:

    > There is a pointer variable 'x'.
    >
    > For what type of 'x' would the following show a write access on 'x'
    >
    > std::cout<<*x<<'\n'; //showing write access on x [what's its type?]


    What does "showing write access on x" mean?

    > I could not think of any possible situation apart from overloaded '*'
    > operator having write operation inside the definition itself.


    You can't overload *. I can't see how x could me modified here, but note
    that anything can happen inside the version of operator<<(ostream&,...)
    called at that point. Here is an example:

    class X { ... };
    class Y {
    public:
    Y(const X & x) { ... }
    };
    ostream & operator<<(ostream & os, const Y & y) {...}

    If x is of type X*, your line of code may well call the version of op<<
    on Y, which in turn can do anything. This is not a write access to x,
    but still execution of an arbitrary amount of code.

    -- Alain.
     
    Alain Ketterlin, Jun 3, 2012
    #3
  4. Paradigm

    Jamie Guest

    Do you know what the "word" 'paradigm' means?

    (Deal with it, I top-posted, on purpose).

    "Paradigm" <> wrote in message
    news:...
    > Hi
    >
    > Here is the scenario:
    >
    > There is a pointer variable 'x'.
    >
    > For what type of 'x' would the following show a write access on 'x'
    >
    > std::cout<<*x<<'\n'; //showing write access on x [what's its type?]
    >
    > I could not think of any possible situation apart from overloaded '*'
    > operator having write operation inside the definition itself.
    >
    > Hope my question is clear.
    > Thanks
     
    Jamie, Jul 15, 2012
    #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. SL
    Replies:
    0
    Views:
    549
  2. Brian Stubblefield

    struct and multiple indirection for a variable

    Brian Stubblefield, May 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    497
    Brian Stubblefield
    May 25, 2004
  3. Marty
    Replies:
    5
    Views:
    700
    Marty
    Aug 21, 2006
  4. Ethan Furman

    attribute access and indirection

    Ethan Furman, Oct 22, 2009, in forum: Python
    Replies:
    0
    Views:
    294
    Ethan Furman
    Oct 22, 2009
  5. Matt Lawrence

    DSL and indirection question

    Matt Lawrence, Oct 25, 2010, in forum: Ruby
    Replies:
    5
    Views:
    158
    Robert Klemme
    Oct 26, 2010
Loading...

Share This Page