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).
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
struct or class, it doesn't really matter that much, structs can have constructors and member functions just like classes do.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens