程序警告问题,teacher

img


我的程序具体应该怎么改,我在类中加了拷贝构造函数声明在类外定义拷贝构造函数。

很简单,你构造函数用的引用参数,不可以实参是常量字符串
878行
string temp ="teacher";
tempt是构造函数的参数

字符串字面常量存在与静态内存区,属于const类型,不可更改,而作为带参构造接收参数是一个普通的指针,属性不同的。
你可以考虑用这种方式:

#include <iostream>
#include <string>
using namespace std;

class String
{
public: 
    String(char p[])
    {
        cout << p << endl;;
    }
};
int main() {
    char b[] = "aaa";
    String str(b);
    system("pause");
    return 0;
}