I’m trying to create a constructor for a custom type, but for some reason, it’s trying to call, what I’m guessing is the constructor in the constructor definition of another class.. Couldn’t find anything which fits the same symptoms I’m having in any other questions, also as I may not know what I’m looking for.
When I call:
LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);
in main.cpp, in LatLngBounds.cpp I get "No matching funciton for call to ‘LatLng:LatLng()" thrown twice on the line for:
LatLngBounds::LatLngBounds(LatLng &newSouthWest, LatLng &newNorthEast)
Anyone got any ideas?
Drew J. Sonne.
IDE: Xcode 3.2 (Targeted to Debug 10.5)
OS: OSX 10.6
Compiler: GCC 4.2
Arch: x86_64
main.cpp:
std::vector<std::string> argVector;
... fill up my argVector with strings..
vector<double> boundsVector = explodeStringToDouble(argVector[i]);
LatLng boundsNorthEast(0, boundsVector[0], boundsVector[1]);
LatLng boundsSouthWest(0, boundsVector[2], boundsVector[3]);
LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);
LatLngBounds.h
#ifndef __LATLNGBOUNDS
#define __LATLNGBOUNDS
#include "LatLng.h"
class LatLngBounds {
private:
LatLng northEast;
LatLng southWest;
public:
LatLngBounds(LatLng&,LatLng&);
};
#endif
LatLngBounds.cpp
#include "LatLngBounds.h"
#include "LatLng.h"
LatLngBounds::LatLngBounds(LatLng &newSouthWest, LatLng &newNorthEast)
{
this->southWest = newSouthWest;
this->northEast = newNorthEast;
};
LatLng.h
#ifndef __LATLNGDEF
#define __LATLNGDEF
class LatLng {
public:
LatLng(int,double,double);
private:
double lat, lng;
int id;
};
#endif
LatLng.cpp
#include "LatLng.h"
LatLng::LatLng(int newId, double newLat, double newLng)
{
/* Grab our arguments */
id = newId;
lat = newLat;
lng = newLng;
};
In your class you have two instances of LatLng objects. In order to construct your object, the compiler also needs to construct them.
Since class LatLng does not have a default constructor, you need to explicitly tell the compiler how to construct those object: