不能在c ++中使用构造函数初始化对象

Pho*_*ton -1 c++ constructor object codeblocks

   #include <iostream>
using namespace std;

class Book
{
public:
Book(const string& ISBN,const string& title,const string& author,const string& cprDate,const bool& ch);
void checkBook(void);
void uncheckBook(void);
string ISBN(){return I;};
string title(){return t;};
string author(){return a;};
string cprDate(){return c;};
bool isChecked(){return check;};
private:
string I;   //ISBN
string t;   //title
string a;   //author
string c;   //copyright date
bool check; //is checked?
};

Book::Book(const string& ISBN,const string& title,const string& author,const string& cprDate,const bool& ch){
I=ISBN;
t=title;
a=author;
c=cprDate;
check=ch;
}

void Book::checkBook(void)
{
check=true;
}
void Book::uncheckBook(void)
{
check=false;
}
int main()
{
Book eragon{"ISBN:19851654-1851651-156115-156156","Eragonas","Paolini","2007",true};
//^This does not compile, it gives 2 errors: expected primary-expression before eragon
//and expected ';' before semicolon
return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在从"编程 - 使用C++的原理和实践"一书中进行练习,并且我坚持第9章练习5:

本练习和接下来的几个练习要求您设计和实现Book类,例如您可以将其视为库的软件的一部分.Class Book应包含ISBN,标题,作者和版权日期的成员.还存储有关书籍是否已签出的数据.创建用于返回这些数据值的函数.创建用于检入和退出书籍的功能.对书中输入的数据进行简单验证; 例如,仅接受nn-nx形式的ISBN,其中n是整数,x是数字或字母.将ISBN存储为字符串.

我甚至无法初始化Book对象:/

Dar*_*con 6

您的编译器不是C++ 11模式.的{...}初始化程序语法在C++ 11是新的.请参阅此问题以在CodeBlocks中启用C++ 11支持.

另一个选择是使用C++ 03语法,但如果本书使用C++ 11,您可能需要最终打开它.C++ 03语法是:

Book eragon("ISBN:19851654-1851651-156115-156156","Eragonas","Paolini","2007",true);
Run Code Online (Sandbox Code Playgroud)