I have been using this class :
class DogTrainer
{
public:
DogTrainer(int identity,const std::string& nom, const std::vector<Dog*> dogz) :
idD(identity),
name(nom),
trainees(dogz)
{ };
~DogTrainer();
private:
int idD;
string name;
std::vector<Dog*> trainees;
};
but sometimes when I want to instantiate a new object, I don’t need to pass a “trainees” parameter, so I want to have the possiblity to do this
DogTrainer* Trainer=new DogTrainer(my_id, my_name);
therefore I tried to change in my DogTrainer constructor
DogTrainer(int identity,const std::string& nom, const std::vector<Dog*> dogz="") :
idD(identity),
name(nom),
trainees(dogz)
{ };
but it didn’t work so any help please !
Declare your constructor as:
""is aconst char*, and astd::vectoris not constructible from that.Incidentally, there’s not much point in
dogzbeing aconst std::vector<Dog*>. Either make it non-constor make it aconstreference.