开发者

Structure of vectors C++

is there a way to clear a structure of vectors at a time using a single statement ?开发者_JAVA百科 i.e. struct AStruct { vector StringList; vector DistanceList; }A;

i want both the vectors using a single statement.


Sure:

AStruct a;
// stuff
a = AStruct();  // clear it

However, I would probably give myself a function:

struct AStruct { 
   vector <string> StringList; 
   vector <string> DistanceList; }
   void clear() {
       StringList.clear();
       DistanceList.clear();
   }
};

You can then say:

AStruct a;
// stuff
a.clear();  // clear it

which is perhaps easier to understand.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜