Friday 15 August 2014

c++ - Returning a vector reference properly -


I am working on a project now and I am confused about how confused it is.

  class unit: public entity {string name; Intel HP; Int mp; Int AG; Int Spr; Int deef; Int hectic; Int LVL; Int app; Std :: vector & lt; Integer & gt; States; String unit type; Public: Int Gethp () {return Himachal Pradesh}; C GetMP () {return MP}; Int Getaway () {Ridge AG}; Int GetSpr () {return SPR}; Int GetDef () {Return Def}; Int getet () {return act}; Int hotel () {returns lvl}; Int GetExp () {return exp}; Std :: vector & lt; Integer & gt; & Amp; Gatestates () {return and state}; String GetUnitType () {return unitType}; Virtual Zero SetHP (int newValue); Virtual Zero SetMP (Int NewView); Virtual Zero SetAgi (int newValue); Virtual Zero SetSpr (int newValue); Virtual Zero SetDef (int newValue); Virtual Zero SetAtk (int newValue); Virtual Zero SetLvl (Int newValue); Virtual Zero SetExp (Int NewView);   

I need to re-reference the "std :: vector states" so that I can repeat through it and find values. I believe that I should use a set because I have only one value and can not be repeated, but I will save it later "std :: vector and getstates () {return and state}" correct? Should it be changed to "std :: vector and const getstates () {return and state}" or am I completely off? I had seen the post here on this, but he did not respond specifically to my question because they used it in the same way.

No, The syntax is errors.

  std :: vector  gatestates () {returns states;}   

is correct.

It should be changed to

- it is up to you to decide if you return non-concent references, whatever the vector requests, He will be able to change it. If you return the conferencing refrence, The meaning of declaring this method is

  const std :: vector & gt; int & gt; GetStates () const {returns states;}   

The second const indicates that when you call this function, the internal state of the object will not change.

No comments:

Post a Comment