Dynamic array of objects in C ++

I am trying to create a dynamic array of objects similar to ArrayLists in Java. I am new to C ++ and cannot make it work.

class Album{

private:

public:
    void addPhoto(Photo p){

    }

};

What should my private datamember look like and how do I add pto it? And for some reason do I need a pointer?

0
source share
4 answers

The functionality you are looking for has already reached the classes in the stl collection , and without knowing that you are using the application, you will have to tell you about the weather whether you need a pointer or not.

The basic layout of your base container might be something like this.

class Album{    

public:
    void addPhoto(Photo p){
         Photos.push_back(p); 
    }
private:
    std::vector<Photo> Photos; 

};
+3
source

You should use std :: vector .

+3

std::vector, ArrayList. (... , - )

+1

@fontanini , , .

, , . ++ , .

. , ++ STL, , :

- STL " STL Stephan T Lavavej"

+1

All Articles