c ++构造函数和方法实现

时间:2017-12-13 23:21:49

标签: c++

我在实施课程的这个过程中遇到了困难。 下面是我的代码,使用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

感谢您的帮助!

1 个答案:

答案 0 :(得分:-1)

错误可能是因为您对参数使用与成员变量相同的名称 - 编译器可能理解与您想要的不同的东西。
重命名参数,例如n而不是name,并且您不需要this->,错误就会消失。

相关问题