嗨我遇到了动态指针的问题,因为我得到了未定义的引用错误。 这是我的代码段:
void FlyingUnit::addFall( const char* location, int day, int month, int year )
{
if(fallCount >= MAX_FALLS)
{
cout<<"Cannot add MAX_FALLS raggiunti ";
}
else
{
falls[fallCount].setLocation(location); //Dynamic pointer problem
falls[fallCount].setDay(day);
falls[fallCount].setMonth(month);
falls[fallCount].setYear(year);
fallCount++;
}
}
void Fall::setLocation(const char* location)
{
if( this->location != nullptr )
{
delete [ ] this->location;
}
this->location = new char[ strlen(location)+1 ];
strcpy( this->location, location);
}