小编shb*_*hbz的帖子

我的练习代码中的C++代码错误

你能帮帮我解决这个问题吗?

#include <iostream>
#include <cstring>

using namespace std;

class A
{
public:
    char str[4];

    A()
    {
        str = "C++";
        cout << "Constructor A" << endl;
    }

    void display()
    {
        cout << str << " is your name" << endl;
    }
};

int main()
{
    A a;
    a.display();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

它给出了以下错误:

**************************Error********** 
StringProg.cpp:9: error: ISO C++ forbids initialization of member "str" 
StringProg.cpp:9: error: making "str" static StringProg.cpp:9: error: invalid in-class initialization of static data member of non-integral type "char [4]" …
Run Code Online (Sandbox Code Playgroud)

c++

-6
推荐指数
1
解决办法
127
查看次数

标签 统计

c++ ×1