问题遇到的现象和发生背景
c++,书上第四题,一个问题是不存在默认函数怎么解决;二是题目规定要用给定长度char数组,不知道后面主函数中的对象如何声明。
问题相关代码,请勿粘贴截图
#include
#include<string.h>
using namespace std;
class people {
public:
class date {
public:
date(int year, int month, int day) { YEAR = year; MONTH = month; DAY = day; };
date operator = (const date& p) {
YEAR = p.YEAR; MONTH = p.MONTH; DAY = p.DAY; return *this;
}
date(date const & P) { };
~date() {};
void print() { cout << YEAR << "-" << MONTH << "-" << DAY; }
private:
int YEAR,MONTH, DAY;
};
people( char name[11], char number[7], char sex[3],date birth, char id[16])
{
strcpy(NAME, name); strcpy(NUMBER, number); strcpy(SEX, sex); BIRTH = birth; strcpy(ID, id);
};
people( people const & D) {};
~people() {};
inline void display() { cout << NAME << " " << NUMBER << " " << SEX;cout<< " " << ID; };
private:
char NAME[11], NUMBER[7], SEX[3], ID[16];
date BIRTH;
};
void main() {
people::date birth1(2001, 1, 2);
birth1.print();
people A(){};
}
运行结果及报错内容
E0291 类 "people::date" 不存在默认构造函数