Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Indirection operator and write access

Reply
Thread Tools

Indirection operator and write access

 
 
Paradigm
Guest
Posts: n/a
 
      06-02-2012
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-03-2012
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
 
Reply With Quote
 
 
 
 
Alain Ketterlin
Guest
Posts: n/a
 
      06-03-2012
Paradigm <(E-Mail Removed)> 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.
 
Reply With Quote
 
Jamie
Guest
Posts: n/a
 
      07-15-2012
Do you know what the "word" 'paradigm' means?

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

"Paradigm" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DSL and indirection question Matt Lawrence Ruby 5 10-26-2010 07:48 AM
attribute access and indirection Ethan Furman Python 0 10-22-2009 01:21 PM
Indirection operator placement Marty C++ 5 08-21-2006 06:26 PM
[xinclude] How to use indirection in xinclude like "Catalog" in the entity world ? SL XML 0 02-15-2005 01:58 PM
struct and multiple indirection for a variable Brian Stubblefield C Programming 4 05-25-2004 07:14 PM



Advertisments