views:

245

answers:

3

Howdy all,

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 anotehr 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;
};
+3  A: 

Your

LatLngBounds::LatLngBounds(LatLng &newSouthWest, LatLng &newNorthEast)

expects a arguments of type LatLng, passed implictly by reference.

The call LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest); passes two pointers (type LatLng*) instead.

Try instead:

LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
K Prime
And, might I add, it would be a good idea to take the arguments by const reference.
rlbond
s1n
+2  A: 

In your class you have two instances of LatLng objects. In order to construct your object, the compiler also needs to construct them.

class LatLngBounds {
private:
    LatLng northEast;
    LatLng southWest;

Since class LatLng does not have a default constructor, you need to explicitly tell the compiler how to construct those object:

LatLngBounds::LatLongBounds( ..constructor args.. )
    : northEast( ..args for northEast constructor call ..),
      southWest( ..args for southWest constructor call ..)
{
}
R Samuel Klatchko
Drew
A: 

Are you sure the error message you quoted is complete? It indicates, as you pasted, that there is no default empty constructor for LatLng, which the compiler will give you for free.

However, it looks like this line in main.cpp is wrong:

LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);

The definition of the constructor for LatLngBounds are 2 non-const references to LatLng objects but you are passing 2 pointers to LatLng objects. Just pass them without the pointer:

LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
s1n
The compiler will not create a default constructor if there is any other user-defined constructor.
UncleBens