Assuming I want to create a class that prints out current time once every 30 second using legato timers. I have this class defined under the name TimerClass. Now when I want to instantiate this class inside COMPONENT_INIT, if I do it like such can I guarantee that the object will bot be destroyed as soon as COMPONENT_INIT is exited or does this function never exit?
COMPONENT_INIT
{
TimerClass timer;
timer.start_timer();
}
or should this be created as a pointer and dynamically allocated to secure that it never gets destroyed in case COMPONENT_INIT does exit (just in the case of having a main function without a while(1) loop running to guarantee that we never exit:
TimerClass * timer;
COMPONENT_INIT
{
timer = new TimerClass;
timer->start_timer();
}
Note when i tried doing it without the dynamic allocation i got this error right after start_timer function which causes a fault with the process:
Aug 9 15:18:54 | myTimer[4159] | | terminate called after throwing an instance of '
Aug 9 15:18:54 | myTimer[4159] | | std::length_error
Aug 9 15:18:54 | myTimer[4159] | | '
Aug 9 15:18:54 | myTimer[4159] | | what():
Aug 9 15:18:54 | myTimer[4159] | | basic_string::_S_create