Is it possible to set the address of a reference outside of the constructor?
worksCode:int& a = b;
Obviously just changes the value, not the reference.Code:int& a; a = b;
Is it possible to set the address of a reference outside of the constructor?
worksCode:int& a = b;
Obviously just changes the value, not the reference.Code:int& a; a = b;
Do you have something like?
You'll need to use the constructors initializer list:Code:class N { int& a; public: N(int& b) {???} };
Code:N(int& b): a(b) {}
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Does that work outside of constructors, such as a method? Like this:
EDIT: after a test, it turns out i HAVE to do that constructor initializer list thing for every object reference in the class. I guess its because its unsafe to have an unitialized object reference..?Code:class ClassCache { private: ScriptManager& scriptManager; .. .. public: .. .. void Assign(ScriptManager& scriptM): scriptManager(scriptM){} };
Last edited by 39ster; 05-03-2008 at 06:49 AM.
The language forbids you from having uninitialized references.
If you need to change what the reference is referencing, you can always use pointers.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Yeah ill just leave it as a pointer. I can always do * to convert it to a reference or value.