为什么拷贝函数 有cosnt不行呢?
#include <stdlib.h>
#include <string>
#include <iostream>
#include <QDebug>
using namespace std;
class Teacher
{
public:
Teacher(string name = "ti", int _age = 100);
Teacher(const Teacher &tea);
const double m_dPi;
};
Teacher::Teacher(string name, int _age)
:m_dPi(8)
{
cout << "teacher init is run !\n" << endl;
}
Teacher::Teacher(const Teacher &tea)
{
cout <<"Teacher::Teacher(const Teacher &tea)"<<endl;
}
int main()
{
Teacher t;
Teacher t1 = t;
}
我发现 把 const double m_dPi;改成 double m_dPi;就可以了,
但是不知道为什么?