So I am trying to write a class Songs
which takes a string title
, int duration
and a pre-defined scoped enum class Vibe
as parameters:
enum class Vibe {Sad, Happy, Aggressive, InLove};
When Vibe
is empty, I would like it to be automatically set as InLove
.
Wrote constructors which either title and duration oder title, duration and Vibe. When Vibe is empty, I want it set to InLove
automatically. So I tried to use a default constructor like this:
Song::Song(const string& title, const int& duration, const Vibe& vibe = vibe::InLove) : title{title}, duration{duration}, vibe{vibe} {
//conditions for constructors
};
Song::Song(const string& title, const int& duration) : title{title}, duration{duration} {
//conditions & runtime_errors again
};
Compiling works but it just takes the first parameter of the Enumeration Sad
as a default when Vibe
is left empty.
I tried this:
vector<Song> sl;
sl.push_back({"Still loving you",386});
s1 should take the parameters song = "Still loving you"
, duration = 386
and vibe = InLove
, however it ends up having song = "Still loving you"
, duration = 386
and vibe = Sad
.
Could someone tell me what I’m doing wrong?
11