ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

‘getPrivateNodeHandle’ and ‘getNodeHandle’ as class constructor parameters [closed]

asked 2016-11-16 10:16:11 -0500

ROSfc gravatar image

updated 2016-11-17 04:58:30 -0500


I have the following constructor for a non nodelet class.

 Chor::Chor(ros::NodeHandle &_nh , ros::NodeHandle &_nhPriv):nh_(_nh),nhPriv_(_nhPriv)

I want to pass nodeHandle from the nodelet to the class above. The class above is instatiated as private inside the nodelet. In my nodelet class I do

 Chor chor_nodelet(getNodeHandle(),getPrivateNodeHandle());

{ ..

But I get the following error

error: ‘getNodeHandle’ is not a type
error: ‘getPrivateNodeHandle’ is not a type

What is wrong here ?

edit retag flag offensive reopen merge delete

Closed for the following reason too localized by ROSfc
close date 2016-11-18 02:25:09.359581

1 Answer

Sort by » oldest newest most voted

answered 2016-11-16 12:05:06 -0500

ahendrix gravatar image

In the context where you're trying to call your constructor and getNodeHandle(), there is no function named getNodeHandle().

Without seeing the full context, I can't give any more specific advice.

edit flag offensive delete link more


Sorry for the poor description. I have edited my description, does it help ?

ROSfc gravatar image ROSfc  ( 2016-11-17 04:59:48 -0500 )edit

That's not how you call the constructor on a class member. I think you want to use an initializer list instead:

ahendrix gravatar image ahendrix  ( 2016-11-17 10:18:44 -0500 )edit

I moved the constructor from the private to the onInit() region as is. And it works now, there was nothing wrong with the constructor, but I guess getNodeHandle() is inside onInit() and does not exist outside it. Although I can't find documentation that says so.

ROSfc gravatar image ROSfc  ( 2016-11-18 02:24:17 -0500 )edit

This is pretty basic C++: you can't call functions in the declaration of a function; only in the function definition.

ahendrix gravatar image ahendrix  ( 2016-11-18 11:31:59 -0500 )edit

I have been searching for hrs for this "pretty basic C++" rule that doesn't allow "definition of the member variable by calling functions" as I interpret what you are trying to say from your statement above. I agree what you are saying maybe totally true. But I would have loved to see some definitio

ROSfc gravatar image ROSfc  ( 2016-11-21 04:12:58 -0500 )edit

Question Tools

1 follower


Asked: 2016-11-16 10:16:11 -0500

Seen: 660 times

Last updated: Nov 17 '16