What is the C ++ C # Collection <T> equivalent and how do you use it?

I need to store a list / set / array of dynamically created objects of a specific base type in C ++ (and I'm new to C ++). In C #, I would use a common collection, what do I use in C ++?

I know I can use an array:

SomeBase* _anArrayOfBase = new SomeBase[max];

But I don’t get anything “free” with this - in other words, I cannot iterate over it, it does not expand automatically and so on.

So what are the other options?

thanks

+3
source share
7 answers

std::vector, , . , , , . ( , )

std:: list - , , , , , , .
deque , .

std:: deque, , , deque , , , deque . , , .

+17

.

#include <vector>

int main()
{
  std::vector<SomeBase*> baseVector;
  baseVector.push_back(new SomeBase());
}

++ STL. .

+9

std::vector<SomeBase>
std::list<SomeBase>

std::vector<boost::shared_ptr<SomeBase>>
std::list<boost::shared_ptr<SomeBase>>
+4

, S++ L , ++ ( Chaoz ).

++ SomeBase*, SomeBase. , . , .

#, , "SomeBase MyInstance" - . ++ "SomeBase* MyPointer" "SomeBase& MyReference".

+2

vector. .

+1

std:: deque. - , . . , , . , .; -)

, STL. STL - , "" ++. . !

+1

STL. std::vector std:: set, . .

0

Source: https://habr.com/ru/post/1724877/


All Articles