所以我对 C++ 很陌生,并且有动态语言的背景,这可能是一个新手问题。我试图写一个古老的练习,见下文:
class Person
{
public:
Person(char n[], int a) {
name = n;
age = a;
}
int age;
char name[];
};
int main(int argc, char const *argv[])
{
Person p("John", 25);
return 0;
}
这会引发错误:
main.cpp(8) : error C2440: '=' : cannot convert from 'char []' to 'char []'
There are no conversions to array types, although there are conversions
to references or pointers to arrays
为什么需要从同一类型转换?顺便说一句,这是我的完整代码和完整错误。任何帮助表示赞赏!