From: David L <davlew@ma...> - 2007-02-25 17:35:28
I want to define functions such as "setturnrate()" that contain statements such as
where robot is a PlayerClient, or such as
if (bp.color = red) ...;
where bp is a BlobfinderProxy.
If I create (or construct or initialize, I don't know the correct terminology) the PlayerClient and BlobfinderProxy within main(int argc, *argv) using for example
PlayerClient robot(gHostname, gPort);
BlobfinderProxy bp(&robot, 0);
I can run the program with a specified port number, but if I try to add functions to the program I get a compile time error saying that the objects (robot or bp) were not declared within the scope of the added function.
But if I put the lines that create the playerclient and proxy objects in the header, before the function main(), then when I run the program with a specified port number the port number is ignored and the playerclient is accepted on the default port 6665.
So how can I make the playerclient and proxies available globally and still specify the port when I give the command to run the program? (I don't want to write the port number into the program because I will be using the same program for many robots each running on a different port).
From: Brian Gerkey <brian@ge...> - 2007-02-27 18:28:25
On Feb 25, 2007, at 9:34 AM, David L wrote:
> So how can I make the playerclient and proxies available globally
> and still specify the port when I give the command to run the
> program? (I don't want to write the port number into the program
> because I will be using the same program for many robots each
> running on a different port).
Declare the objects globally (i.e., outside of any function) as
Then construct them in main(), once you know the appropriate info:
int main(int argc, char** argv)
robot = new PlayerClient(gHostname, gPort);
bp = new BlobfinderProxy(robot, 0);
Note that your 'robot' and 'bp' are now pointers, not objects, which
means that you'll access their members with -> instead of .
Note also that this is basic C++ programming stuff, independent of
Player. You might want to check out some of the various C++