T
Tim Clacy
Am I correct in think that you can't re-assign a reference to a different
object? If so, what should happen here:
struct A
{
DoSomeThing();
};
A& GetNextA();
while (1)
{
A& a = GetNextA();
a.DoSomeThing();
}
Does reference 'a' only get assigned first time around the loop and,
thereafter, object 'a' gets assigned to the next 'A'... or is 'a' connected
to a different 'A' every time around the loop? What about this:
while (1)
{
{
A& a = GetNextA();
a.DoSomeThing();
}
}
Surely, 'a' would now be different every time around the loop (because the
scope of 'a' ends before looping?
On a related note, is it possible to prevent a reference to a class
instance? Similarly, is it possible to prevent the address of an instance
from being taken?
What I'm looking for is a way to implement a 'Reference<T>' class. In other
words, some kind of class like a smart-pointer except that the 'Reference'
is the only way to access the object to which it refers. I want to prevent
'address-of' and references and use the 'Reference' as a means to manage
object life-time.
Any insight or links to good articles will be very much appreciated.
Regards
Tim
object? If so, what should happen here:
struct A
{
DoSomeThing();
};
A& GetNextA();
while (1)
{
A& a = GetNextA();
a.DoSomeThing();
}
Does reference 'a' only get assigned first time around the loop and,
thereafter, object 'a' gets assigned to the next 'A'... or is 'a' connected
to a different 'A' every time around the loop? What about this:
while (1)
{
{
A& a = GetNextA();
a.DoSomeThing();
}
}
Surely, 'a' would now be different every time around the loop (because the
scope of 'a' ends before looping?
On a related note, is it possible to prevent a reference to a class
instance? Similarly, is it possible to prevent the address of an instance
from being taken?
What I'm looking for is a way to implement a 'Reference<T>' class. In other
words, some kind of class like a smart-pointer except that the 'Reference'
is the only way to access the object to which it refers. I want to prevent
'address-of' and references and use the 'Reference' as a means to manage
object life-time.
Any insight or links to good articles will be very much appreciated.
Regards
Tim