string initialization in constructor

Hi, today i was doing one exercise and i wrote this constructor for my Book class where one of the parameters was string.
Book::Book(std::string a) : author{a} {}
Than typing Book my_book("Johny");

I was not allowed to do this and i kept getting this error
Error 2 error C2797: 'Book::author': list initialization inside member initializer list or non-static data member initializer is not implemented

This usually works for all the other data types, even worked for my Chrono::Date. Than i tryed this and it finally worked
Book::Book(std::string a){ author = a;}
Can anyone explain to me why 1st version is not working?
Last edited on
Braces. C++11 made them work here and there, but there are always quirks.

Try Book::Book(std::string a) : author(a) {}


Note:
1
2
3
std::string foo;
std::string bar ( foo ); // calls: string (const string&);
std::string gaz { foo }; // calls: string (initializer_list<char>); 
Cool :) Thank you very much :)
Topic archived. No new replies allowed.