我在实施课程的这个过程中遇到了困难。 下面是我的代码,使用g ++编译给我一个错误,如下面的代码。
Contact::Contact(const char * name, const char * address, const char *
tel) {
name = new char[strlen(name) + 1];
address = new char[strlen(address) + 1];
tel = new char[strlen(tel) + 1];
strcpy(this->name, name);
strcpy(this->address, address);
strcpy(this->tel, tel);
}
错误是
Contact.cpp:9: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
感谢您的帮助!
答案 0 :(得分:-1)
错误可能是因为您对参数使用与成员变量相同的名称 - 编译器可能理解与您想要的不同的东西。
重命名参数,例如n
而不是name
,并且您不需要this->
,错误就会消失。