C++ 使用自定义类作为参数的构造函数,抛出';没有用于调用…';
我试图为自定义类型创建构造函数,但出于某种原因,它试图调用,我猜是另一个类的构造函数定义中的构造函数。。找不到任何符合我在任何其他问题上的症状的东西,也因为我可能不知道我在寻找什么 当我打电话时:C++ 使用自定义类作为参数的构造函数,抛出';没有用于调用…';,c++,constructor,default-constructor,C++,Constructor,Default Constructor,我试图为自定义类型创建构造函数,但出于某种原因,它试图调用,我猜是另一个类的构造函数定义中的构造函数。。找不到任何符合我在任何其他问题上的症状的东西,也因为我可能不知道我在寻找什么 当我打电话时: LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest); 在main.cpp中,在LatLngBounds.cpp中,我在以下行中两次抛出“没有匹配的函数用于调用'LatLng:LatLng()”: LatLngB
LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);
在main.cpp中,在LatLngBounds.cpp中,我在以下行中两次抛出“没有匹配的函数用于调用'LatLng:LatLng()”:
LatLngBounds::LatLngBounds(LatLng &newSouthWest, LatLng &newNorthEast)
有人有什么想法吗
德鲁·J·索恩
IDE:Xcode 3.2(针对调试10.5)操作系统:OSX 10.6
编译器:GCC 4.2
拱门:x86_64
main.cpp: LatLngBounds.cpp LatLng.h LatLng.cpp 你的 需要类型为
LatLng
的参数,通过引用隐式传递
调用LatLngBounds clusterBounds(&boundsNorthEast,&boundsSouthWest)代码>传递两个指针(键入LatLng*
)
请尝试:
LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
你的
需要类型为LatLng
的参数,通过引用隐式传递
调用LatLngBounds clusterBounds(&boundsNorthEast,&boundsSouthWest)代码>传递两个指针(键入LatLng*
)
请尝试:
LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
在类中,有两个LatLng对象的实例。为了构造对象,编译器还需要构造它们
class LatLngBounds {
private:
LatLng northEast;
LatLng southWest;
由于类LatLng没有默认构造函数,因此需要显式地告诉编译器如何构造这些对象:
LatLngBounds::LatLongBounds( ..constructor args.. )
: northEast( ..args for northEast constructor call ..),
southWest( ..args for southWest constructor call ..)
{
}
在类中,有两个LatLng对象的实例。为了构造对象,编译器还需要构造它们
class LatLngBounds {
private:
LatLng northEast;
LatLng southWest;
由于类LatLng没有默认构造函数,因此需要显式地告诉编译器如何构造这些对象:
LatLngBounds::LatLongBounds( ..constructor args.. )
: northEast( ..args for northEast constructor call ..),
southWest( ..args for southWest constructor call ..)
{
}
您确定您引用的错误消息是完整的吗?粘贴时,它表明LatLng没有默认的空构造函数,编译器将免费提供给您
但是,main.cpp中的这一行似乎是错误的:
LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);
LatLngBounds构造函数的定义是对LatLng对象的2个非常量引用,但您将向LatLng对象传递2个指针。只需在不使用指针的情况下传递它们:
LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
您确定您引用的错误消息是完整的吗?粘贴时,它表明LatLng没有默认的空构造函数,编译器将免费提供给您
但是,main.cpp中的这一行似乎是错误的:
LatLngBounds clusterBounds(&boundsNorthEast, &boundsSouthWest);
LatLngBounds构造函数的定义是对LatLng对象的2个非常量引用,但您将向LatLng对象传递2个指针。只需在不使用指针的情况下传递它们:
LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);
还有,我想补充一点,通过常量引用获取论点是个好主意。同意,常量LatLng&会更好。我想补充一点,通过常量引用获取论点是个好主意。同意,常量LatLng&会更好。太棒了。它也是函数调用中的&,但这是我找不到的。谢谢,太棒了。它也是函数调用中的&,但这是我找不到的。谢谢。如果有任何其他用户定义的构造函数,编译器将不会创建默认构造函数。如果有任何其他用户定义的构造函数,编译器将不会创建默认构造函数。
LatLngBounds clusterBounds(boundsNorthEast, boundsSouthWest);