C++ 如何为指向类的指针向量构建构造函数

C++ 如何为指向类的指针向量构建构造函数,c++,class,pointers,vector,constructor,C++,Class,Pointers,Vector,Constructor,我需要为指向类的指针向量构建一个构造函数 我的班级是: class Song { string song_name; string auther_name; int popularity; SongStructure song_format; int song_length; int lengths[size]; bool first_condition_true(); bool second_condition_t

我需要为指向类的指针向量构建一个构造函数

我的班级是:

class Song {

    string song_name;

    string auther_name;

    int popularity;

    SongStructure song_format;

    int song_length;

    int lengths[size];

    bool first_condition_true();

    bool second_condition_true(int index);

    }

};
我的向量是:

vector<Song*> play_list;
矢量播放列表;

引入了新的标准C++11/0x初始值设定项列表:

我假设您想要创建一个SongBook类,其中包含一个歌曲指针向量和其他信息。 它们可以这样使用:

类文件:

class SongBook {
    vector<Song*> songlist;
    string name;

    // Constructor
    SongBook(std::initializer_list<Song*> songs) : songlist(songs) {}
}

你的向量有一个可以使用的构造函数。(它为指针创建位置)。您所要求的可能是一种让指针指向某首有效歌曲的方法。您将需要在某个循环中执行此操作(可能是STL“循环”)。但是你可能不需要,因为你的歌是可以合法复制的!?。您可以使用
向量

实际问题是什么?vector已经有了一个构造函数,您不必创建它。是的,您的问题是?
SongBook book({new Song(...), new Song(...), new Song(...)});