【发布时间】:2015-04-12 10:44:39
【问题描述】:
尝试用 C++ 为我的大学构建一个项目。 尝试使用我在 Main.cpp 中为 MyDate 创建的方法 它不断让我堆栈 o/f 和“表达式块类型是有效的”错误。
main.cpp:
date1.setDay(8);
date1.setMonth(4);
date1.setYear(1994);
date1.setCmnt("Bday"); //problem with chars and pointers..
date1.print();
//Copy Constructor
date2 = date1;
date2.print();
我的日期.h:
void setCmnt(char *cmnt){
if (cmnt!=nullptr)
*c = *cmnt;
};
复制常量:
day=Date.day;
month=Date.month;
year=Date.year;
if (Date.c != nullptr)
{
c = new char[strlen(Date.c) + 1];
strcpy(c, Date.c);
//*c = *Date.c;
}
tnx 非常感谢你们的帮助!!
【问题讨论】:
标签: c++ pointers methods char copy-constructor