Редактировать: мой отладчик лгал мне. Это все не имеет значения
Привет всем,
Я посмотрел на Добавление элемента в вектор , но в моем случае это бесполезно.
Я пытаюсь добавить элемент (пользовательский класс LatLng) в другой объект (Cluster) из третьего объекта (ClusterManager).
Когда я передаю свой LatLng в Cluster (последняя строка ClusterManager.cpp) и перехожу в Cluster :: addLocation, в конце выполнения функции gdb говорит, что мой новый LatLng был добавлен в Cluster, но в тот момент, когда я перехожу обратно в область видимости самого высокого класса, ClusterManager, новый LatLng, добавленный к вектору 'locStore', отсутствует ни во время выполнения, ни в отладке.
Есть идеи?
DJS.
DE: Xcode 3.2 (предназначен для отладки 10.5)
ОС: OSX 10.6
Компилятор: GCC 4.2
Арка: x86_64
ClusterManager.cpp (откуда все это вызывается):
void ClusterManager::assignPointsToNearestCluster()
{
//Iterate through the points.
for (int i = 0; i < locationStore.size(); i++)
{
double closestClusterDistance = 100.1;
// Make sure to chuck the shits if we don't find a cluster.
int closestCluster = -1;
int numClusters = clusterStore.size();
// Iterate through the clusters.
for (int j = 0; j < numClusters; j++) {
double thisDistance = locationStore[i].getDistanceToPoint( *(clusterStore[j].getCentroid()) );
// If there's a closer cluster, make note of it.
if (thisDistance < closestClusterDistance) {
closestClusterDistance = thisDistance;
closestCluster = j;
}
}
// Remember the penultiment closest cluster.
this->clusterStore[closestCluster].addLocation( this->locationStore[i] );
}
}
ClusterManager.h
#include "Cluster.h"
#include "LatLng.h"
#include <vector>
class ClusterManager{
private:
std::vector<Cluster> clusterStore;
std::vector<LatLng> locationStore;
public:
ClusterManager();
void assignPointsToNearestCluster();
void addLocation(int,double,double);
};
Cluster.h:
#include <vector>
#include <string>
#include "LatLng.h"
class Cluster {
private:
std::vector<LatLng> locStore;
LatLng newCentroid;
bool lockCentroid;
int clusterSize;
int clusterID;
public:
Cluster(int,LatLng&);
void addLocation(LatLng&);
LatLng* getCentroid();
};
Cluster.cpp
Cluster::Cluster(int newId, LatLng &startPoint)
{
this->clusterID = newId;
this->newCentroid = startPoint;
};
void Cluster::addLocation(LatLng &newLocation)
{
(this->locStore).push_back( newLocation );
};
LatLng* Cluster::getCentroid()
{
return &newCentroid;
};