FW: [CST-2] Address taken variable
Tom Puverle
tp225@cam.ac.uk
Thu, 30 May 2002 00:10:03 +0100
> 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