Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 448201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:38:46+00:00 2026-05-12T21:38:46+00:00

Edit: My debugger was lying to me. This is all irrelevant Howdy all, I

  • 0

Edit: My debugger was lying to me. This is all irrelevant

Howdy all,

I had a peek at Adding element to vector, but it’s not helpful for my case.

I’m trying to add an element (custom class LatLng) to another object (Cluster) from a third object (ClusterManager).

When I pass my LatLng to Cluster (last line of ClusterManager.cpp), and jump into Cluster::addLocation, at the end of the function execution gdb says my new LatLng has been added to Cluster, but the moment I jump back into the scope of the highest class, ClusterManager, the new LatLng added to the vector ‘locStore’ is not present in either runtime or debug.

Any ideas?

DJS.

DE: Xcode 3.2 (Targeted to Debug 10.5)
OS: OSX 10.6
Compiler: GCC 4.2
Arch: x86_64

ClusterManager.cpp (where it’s all being called from):

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;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:38:46+00:00Added an answer on May 12, 2026 at 9:38 pm

    The debugger is possibly lying. I’ve found Xcode has issues has viewing the contents of vectors, try using some asserts to make sure the vector in question is actually being filled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.