Я работал над проектом C ++ с Visual Studio 2010, и все было хорошо, но когда я пытался запустить свою программу с xcode 4, это вызывает исключение Bas_Access.Я думаю, что это из-за утечки памяти, но я не уверен, как решить проблему.У меня есть следующая функция:
// Search is my class with x and y as members and here's is a constructor
// that I cretae in my Search.cpp class
Search& Search::operator=( const Search& search )
{
if(this != &search)
{
x = search.x;
y = search.y;
}
return *this;
}
И вот как называется моя функция:
Search searchStart(0,0);
//I created my tempSearch and initialized it with the start Search element
Search tempSearch(searchStart);
//bestSolution is a function that calculates the best neighbour node around the searchStart node, it returns a Search element. And stores it in a list in storage.
Search * tempCurrent=searchStart.bestSolution(&storage);
//Here I call my function
tempSearch=*tempCurrent;
Я просто создаю новый элемент поиска из существующего элемента, но он дает мнеисключение на
x=search.x;
Отлично работает с visual studio.
РЕДАКТИРОВАТЬ: Я только что добавил код, где вызывается моя функция.Извините, что я не могу предоставить полный код, потому что он действительно длинный.
РЕДАКТИРОВАТЬ: Вот моя функция bestSolution:
Search * searchNode::Search::bestSolution(Storage *storage )
{
//listResult is a type defined as std::list<Search *> listResult.
listResult::iterator it, it1;
listResult tempList;
//I've initialized the result element at (0,0) because it was creating problems
// if uninitialized
Search *result=new Search(0,0);
//openList is a simple list of Search elements
if(!storage->openList.empty()){
for(it=storage->openList.begin();it!=storage->openList.end();it++)
{
tempList.push_back((*it));
}
tempList.reverse();
it1=tempList.begin();
// getDistanceCost is a function that calculates the heuristic distance
// between two points and works fine
int fCost=(*it1)->getDistanceCost();
for(it1=storage->openList.begin();it1!=storage->openList.end();it1++)
{
if((*it1)->getDistanceCost()<=fCost){
fCost=(*it1)->getDistanceCost();
result=(*it1);
}
}
}
return result;
}