Re: Reference to void
Frederick Gotham wrote:
There's no such thing as a "reference to void" because there's no such
thing as an object whose type is "void", and therefore a reference cannot
be bound to such a hypothetical object. Consider:
void i;
void &j = i;
Of course there is no object that has the type void. It doesn't have to
be.
Please take a look at the following code:
<code>
class A {};
class Void; // No definition
int main()
{
A a;
Void* p = reinterpret_cast<Void*>( &a );
Void& ref = *p;
A& refA = reinterpret_cast<A&> (ref);
return 0;
}
</code>
Here, there is no object of type Void. But still I can create a
reference to Void, and the use it. Of couse, I can only cast from it,
because I don't have an interface for the type Void.
Why shouldn't the "void" type behave just like this "Void" ?
Best Regards,
Lucian Radu Teodorescu
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]