Undefined reference to parent NON default constructor
I have the parent class
//parent.h
class parent
{
parent(){std::cout << "default parent constructor" << std::endl;} ;
parent(ros::Nodehandel n_) ;
~parent (){} ;
protected :
ros::NodeHandle n ;
}
// parent.cpp
parent::parent(ros::NodeHandel n_): n(n_)
{
std::cout << " parent constructor" << std::endl;
publishers
Subscriber
}
/////////////////////////////////////////////
// child.cpp
class child : public parent
{
child (){std::cout << "default child constructor" << std::endl ; } ;
child (ros::NodeHandle n){std::cout << "child constructor" << std::endl ; }
// child (ros::NodeHandle n):: parent (n) {std::cout << "child constructor" << std::endl ; } // NOT WORKING THERE IS AN ERROR
~child () ;
}
/////////////
int main ( .... )
{
ros::init(argc, argv, "node");
ros::NodeHandle n;
ros::NodeHandle n_priv("~");
double freq;
n_priv.param<double>("frequency", freq, 10.0);
ros::Rate loop_rate(freq);
child prf_obj(n);
while(ros::ok())
{
std::cout << "loop" << std::endl;
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}
For the following code I get the following results:
default parent constructor
child constructor
loop
loop
.
.
.
/////
What I want to is to call the non default constructor for the parent where I define the publisher and subscriber ?? but When I do the following:
child (ros::NodeHandle n):: parent (n) {std::cout << "child constructor" << std::endl ; } // NOT WORKING THERE IS AN ERROR
The ERROR: undefined reference to `parent::parent(ros::NodeHandle&)
I added the parent.h filed in include folder in the package. the parent.cpp and child.cpp are in the src folder in the package. I also added in the Cmakelist
include_directories(include
${catkin_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
add_library(controller
src/parent.cpp
)
add_executable(run_node src/child.cpp)
add_dependencies(run_node ${PROJECT_NAME}_gencfg ${PROJECT_NAME}_generate_messages_cpp)
target_link_libraries(run_node
${catkin_LIBRARIES}
${Boost_LIBRARIES}
)
is there any thing I have to add any where else to fix this problem ???