开发者

Allocating memory to a pointer of a class

开发者 https://www.devze.com 2023-03-08 09:40 出处:网络
QGeoRoutingManager: http://apidocs.meego.com/1.0/qtmobility/qgeoroutingmanager-members.html This class doesn\'t have a constructor.

QGeoRoutingManager: http://apidocs.meego.com/1.0/qtmobility/qgeoroutingmanager-members.html

This class doesn't have a constructor. I have forgotten the way to allocate memory to its pointer.

I did:

QGeoRoutingManager *a = new QGeoRoutingManager ();

This lands in the error:

calculateRoute.cpp:16: error: no matching function for call to ‘QtMobility::QGeoRoutingManager::QGeoRoutingManager()’
../../../../tarBalls/q开发者_JS百科t-mobility-opensource-src-1.2.0/install/include/QtLocation/qgeoroutingmanager.h:91: note: candidates are: QtMobility::QGeoRoutingManager::QGeoRoutingManager(const QtMobility::QGeoRoutingManager&)

What should I pass in there, as per the error message "const QtMobility::QGeoRoutingManager&"


This is a singleton class, you can access it like this:

QGeoServiceProvider::routingManager().

Check the docs


If the class doesn't have a public (default) constructor, you can't (directly) create a new instance of it, neither on the stack nor on the free store (heap). You could only possibly create a copy of an existing one, but the docs don't show a copy ctor available.

Look through the documentation if there is a factory function / class to create instances of that class.


The class QGeoRoutingManager does not have default constructor. The default constructor is one which doesn't take any argument. If it takes, then they're optional (with default value).


The class does have a constructor; all classes have a constructor. The class apparently doesn't have a default constructor. You don't show us the class, so we have to guess, but from the error message, the class does have a copy constructor. Did you provide it? As soon as there are any user defined constructors, the compiler will not generate a default constructor; you have to provide one of those too.


I think you need QGeoRoutingManager * QGeoServiceProvider::routingManager () const

Check here: https://doc-snapshots.qt.io/qt-mobility/qgeoserviceprovider.html

0

精彩评论

暂无评论...
验证码 换一张
取 消