我正在尝试删除向量的内容而我收到错误 - 向量迭代器不可递增,为什么会这样?
这是我的析构函数:
City::~City()
{
vector <Base*>::iterator deleteIterator;
for (deleteIterator = m_basesVector.begin() ; deleteIterator != m_basesVector.end() ; deleteIterator++)
m_basesVector.erase(deleteIterator);
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
嘿,我已经覆盖operator<<,当我试图在打印方法(const)中使用它时,我收到一个错误:
覆盖运算符:
ostream& operator <<(ostream& os, Date& toPrint)
{
return os << toPrint.GetDay() << "/" << toPrint.GetMonth() << "/" << toPrint.GetYear();
}
Run Code Online (Sandbox Code Playgroud)
在哪里我试图使用它:
void TreatmentHistory::TreatmentHistoryPrint() const
{
cout << m_treatmentDate << "\n" << endl;
}
Run Code Online (Sandbox Code Playgroud) 这个例外是什么意思,我该怎么做才能解决它?
我收到一个错误 - 堆损坏,无法弄清楚原因.
我的基地:
H:
class Base
{
public :
Base(char* baseName, char* cityName);
virtual ~Base();
list<Vehicle*>::const_iterator GetEndList();
void PrintAllVehicles(ofstream &ResultFile) const;
char* GetBaseName() const;
char* GetLocation() const;
void InsertNewVehicleToBase(Vehicle* newVehicle);
list<Vehicle*>::const_iterator FindVehicle(char* id);
void RemoveVehicle (list<Vehicle*>::const_iterator beg);
private:
char* m_name;
char* m_location;
list<Vehicle*> m_baseVehicles;
};
Run Code Online (Sandbox Code Playgroud)
cpp:
Base::Base(char* baseName, char* cityName)
{
m_name = new char [strlen(baseName)+1];
strcpy(m_name, baseName);
m_location = new char [strlen(cityName)+1];
strcpy(m_location, cityName);
}
Base::~Base()
{
delete [] m_name;
delete [] m_location;
//m_baseVehicles.clear();
}
Run Code Online (Sandbox Code Playgroud)
军队破坏者:
Army::~Army()
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用多图stl,我迭代我的地图,我没有在地图中找到我想要的对象,现在我想检查我的迭代器是否持有我想要的东西,我有困难因为它它不是空的或什么的.感谢名单!
我正在尝试使用NULL值初始化矩阵的所有单元格,但这里有些错误.
代码 :
vector<vector<Distance*> > distanceMatrix;
for (int i = 0; i < 7 ; i++)
for (int j = 0; j < 7 ; j++)
distanceMatrix[i][j].push_back(NULL);
Run Code Online (Sandbox Code Playgroud)
我敢打赌这是愚蠢的,谢谢你的帮助.