Robotics StackExchange | Archived questions

‘getPrivateNodeHandle’ and ‘getNodeHandle’ as class constructor parameters

Hello,

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

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

onInit()
{ ..
 }

But I get the following error

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

What is wrong here ?

Asked by ROSfc on 2016-11-16 11:16:11 UTC

Comments

Answers

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.

Asked by ahendrix on 2016-11-16 13:05:06 UTC

Comments

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

Asked by ROSfc on 2016-11-17 05:59:48 UTC

That's not how you call the constructor on a class member. I think you want to use an initializer list instead: http://en.cppreference.com/w/cpp/language/initializer_list

Asked by ahendrix on 2016-11-17 11:18:44 UTC

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.

Asked by ROSfc on 2016-11-18 03:24:17 UTC

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

Asked by ahendrix on 2016-11-18 12:31:59 UTC

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

Asked by ROSfc on 2016-11-21 05:12:58 UTC

http://en.cppreference.com/w/cpp/language/class

Asked by ahendrix on 2016-11-21 12:01:33 UTC