当我尝试编译下面的源代码时,遇到了以下错误。有没有人能说明为什么会出现这个错误以及如何修复它呢?
错误 1 错误 C2758: 'A::s_' : 必须在构造函数基类/成员初始化程序中初始化
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
A(string& s) : s_(s) { cout << "A::ctor" << endl; }
A(const A& rhs) { cout << "A::copy" << endl; }
~A() { cout << "A::dtor" << endl; }
A& operator=(const A& rhs) { cout << "A::copyassign" << endl; }
private:
string& s_;
};
int main()
{
return 0;
}