Question

I am having trouble initializing a couple of objects.I am writing a program that will perform frontier based exploration for a mobile robot using Player/Stage simulation 2.0. I have a class called Explorer. The objects I am having difficulty initializing are robot, pp, lp. I look at the reference page online, and I believe it is because there is no assignment operator for this but im hoping there is another way to do it.;

This is my header

#ifndef EXPLORER_H_
#define EXPLORER_H_
#include <libplayerc++/playerc++.h>
#include <iostream>
#include <fstream>
#include <math.h>`
#include <list>
#include "Map.h"

using namespace PlayerCc;
using namespace std;

struct Pose {
double x;
double y;
double theta;
};

struct Frontier {
int startRow;
int startCol;
int endRow;
int endCol;
double score;
};

class Explorer {

public:
Explorer();
void Explore(Map *map);
void performLaserSweep(Map *map);
void detectandgroupFrontiers(Map *map);
Frontier score_pick_Frontier();
void goToFrontier(Frontier f);

private:
PlayerClient robot;
Position2dProxy pp;
LaserProxy *lp;
Pose pose;
list<Frontier> unexploredFrontiers;
};

#endif /* EXPLORER_H_ */

this is my .cc file all that matters is the constructor so that is all i am showing

#include "Explorer.h"

Explorer::Explorer() {

robot = new PlayerClient("127.0.0.1", 6665);
pp = new Position2dProxy(robot, 0);
lp = new LaserProxy(robot, 0);
if (lp == NULL) {
    cerr << "Error initializing LASER" << endl;
    exit(1);
}
pp.SetMotorEnable(true);
}

Thank you in advance for the help

this is the compiler error

Explorer.cc: In constructor ‘Explorer::Explorer()’:
Explorer.cc:11: error: no matching function for call to ‘PlayerCc::Position2dProxy::Position2dProxy()’
/usr/include/player-2.0/libplayerc++/playerc++.h:1566: note: candidates are: PlayerCc::Position2dProxy::Position2dProxy(PlayerCc::PlayerClient*, uint)
/usr/include/player-2.0/libplayerc++/playerc++.h:1553: note:                 PlayerCc::Position2dProxy::Position2dProxy(const PlayerCc::Position2dProxy&)
Explorer.cc:13: error: base operand of ‘->’ has non-pointer type ‘PlayerCc::PlayerClient’
Explorer.cc:13: error: expected unqualified-id before ‘new’
Explorer.cc:13: error: expected ‘;’ before ‘new’
Explorer.cc:14: error: no matching function for call to ‘PlayerCc::Position2dProxy::Position2dProxy(PlayerCc::PlayerClient&, int)’
/usr/include/player-2.0/libplayerc++/playerc++.h:1566: note: candidates are: PlayerCc::Position2dProxy::Position2dProxy(PlayerCc::PlayerClient*, uint)
/usr/include/player-2.0/libplayerc++/playerc++.h:1553: note:                 PlayerCc::Position2dProxy::Position2dProxy(const PlayerCc::Position2dProxy&)
Explorer.cc:15: error: no matching function for call to ‘PlayerCc::LaserProxy::LaserProxy(PlayerCc::PlayerClient&, int)’
/usr/include/player-2.0/libplayerc++/playerc++.h:900: note: candidates are: PlayerCc::LaserProxy::LaserProxy(PlayerCc::PlayerClient*, uint)
/usr/include/player-2.0/libplayerc++/playerc++.h:881: note:                 PlayerCc::LaserProxy::LaserProxy(const PlayerCc::LaserProxy&)
make: *** [all] Error 1
Was it helpful?

Solution

robot in the Explorer class is not a pointer, but you are trying to initialize it with the new keyword:

 robot = new PlayerClient("127.0.0.1", 6665); // this won't work

Same thing with the variable pp.

One of the notes on an error you're getting: note: candidates are: PlayerCc::Position2dProxy::Position2dProxy(PlayerCc::PlayerClient*, uint) also suggest that the constructor needs a PlayerClient pointer.

Try this in the Explorer class:

PlayerClient *robot;

And don't forget do delete it when you are done with it.

An easy way to spot errors like these are looking closely at the error messages. When the error says error: base operand of ‘->’ has non-pointer type it simply means that you are trying to use the pointer operator -> on something that is not a pointer.

OTHER TIPS

Rather than change your class's members to pointers (which comes with its own complications), consider initializing the members rather than assigning to them. Try a Google on "c++ member initializer list" (this one result may be a good place to start: http://www.cplusplus.com/forum/articles/17820/)

From the error it tells candidates are: PlayerCc::Position2dProxy::Position2dProxy(PlayerCc::PlayerClient*, uint) but you are passing robot which is not declared as a pointer. You have declared it as PlayerClient robot; However, you are using robot as a pointer to an object.

So change that to PlayerClient *robot; and this error should be taken care off.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top