How does one initialize a reference within a structure?
Example:
Code:struct _s { char& c; }
This is a discussion on Initializing a reference within a structure within the C++ Programming forums, part of the General Programming Boards category; How does one initialize a reference within a structure? Example: Code: struct _s { char& c; }...
How does one initialize a reference within a structure?
Example:
Code:struct _s { char& c; }
The reference must be initialized when you instantiate the struct. I believe in that case you've shown, you'd have to create a constructor for the struct that initialized the reference to something. There may be a problem with multiple instances of the struct as they might have all there c data members initialized to the same value (You'd have to check that out yourself).
I used to be an adventurer like you... then I took an arrow to the knee.
struct or class, it doesn't really matter that much, structs can have constructors and member functions just like classes do.
I used to be an adventurer like you... then I took an arrow to the knee.