FW: [CST-2] Address taken variable
Barnaby Gray
bgrg2@cam.ac.uk
Thu, 30 May 2002 00:12:01 +0100
Lame. Seriously lame.
Barnaby
On Thu, May 30, 2002 at 12:10:03AM +0100, Tom Puverle wrote:
> > An address taken variable is one whose address has been 'taken' by the
> > program (funnily enough!)
> >
> > E.g. in C
> >
> > a = &b;
> >
> > we set a (usually a pointer) to the address of b :- b is address taken.
>
> Sorry I misinterpreted your last post.
>
> Anyway, it has to be said that in C++ this syntax doesn't always imply
> the taking of the address of b, nor does it always imply an assignment to
> a pointer variable a.
> As an example consider what happens if b is a variable of a class with
> an overloaded operator&()
>
> class SomeType
> {
> ...
> public:
> int operator&()
> {
> hdd_->format();
> return 0;
> }
> private:
> BootHDD * hdd_;
> ...
>
> };
>
> void foobar()
> {
> SomeType b;
> int a = &b; //doesn't quite do what you expect... :)
> }
>
> There is also the other possibility of a not being a pointer type
> but a class with an overloaded operator=()
>
>
> class SomeOtherType
> {
> ...
> public:
> SomeOtherType & operator=(int * rhs )
> {
> //do whatever
> }
> ...
> }
>
> Then
>
> void barfoo()
> {
> SomeType a;
> int b;
> a = &b;
> }
>
> again doesn't do exactly what you expect.
> However, I don't expect them to ask you this in the exam.
> Tom
>
>
> _______________________________________________
> CST-2 mailing list
> CST-2@srcf.ucam.org
> http://www.srcf.ucam.org/mailman/listinfo/cst-2