Home > Back-end >  About the structure of reference types defined in members
About the structure of reference types defined in members

Time:10-10

Just learning c + +, ask a question, a function has multiple vector types of input and output parameters, namely the incoming vector, the function of the vector,
The vector encapsulated in a structure

Typedef struct {
VectorVector} OutputPara;

Void fun1 (OutputPara & amp; The output);

VectorVectorOutputPara output;
The output. The id1=...//refer to id1
The output. Id2=...//refer to id2
Fun1 (output);

Whether can use reference for operation, please? If you can't use references, generally this scenario is how to achieve?
Thank you very much!

CodePudding user response:

Can use references, but the reference must be initialized when definition, reference can't be empty, the reference cannot be modified, that is best after binding can no longer be bound to the other variables,
So in general will be inside the constructor initializes, and a reference is an alias, so consider it refers to the object's lifetime,
Above all, set a class member for reference, rarely,

  • Related