Olá,
Estou escrevendo um projeto em C++. Preciso utilizar atributos de classe (estáticos). Algumas classes do Projeto utilizam funções estáticas sem a necessidade de atributos estáticos. Isso funciona corretamente. Porém, quando precisei criar um servico de tempo e adicionar atributos de estáticos na classe, o codigo não funciona na placa. Contudo, eu testei na simulação e funcionou sem problemas. Além disso, existem outras classes no mesmo projeto que também utilizam atributos estáticos e até agora não tive problemas. Segue o código .h e .cpp.
Hello,
I'm writing a project in C ++. I need to use class attributes (static). Some classes of the Project use static functions without the need for static attributes and this works correctly. However, when I needed to create a service time and add static attributes in this class, the code did not work on the board. However, I have tested in simulation and worked without problems. In addition, there are other classes in the same project that also use static attributes and so far had no problems. Here is the code .h and .cpp
//---------------- Header File (TimeService.h) namespace service { class TimeService : public Service{ public: TimeService(hal::Timer* timer); static void wait(U32 miliseconds); virtual void init(); private: static hal::Timer* timer; static U32 timeCount; }; } //----------------- End Header File (TimeService.h) //---------------- CPP File (TimeService.cpp) hal::Timer* service::TimeService::timer; U32 service::TimeService::timeCount; namespace service { TimeService::TimeService(hal::Timer* timer) { TimeService::timeCount = 0; TimeService::timer = timer; } void TimeService::init() { //DO NOTHING. } void TimeService::wait(U32 miliseconds) { TimeService::timeCount = ((miliseconds* TimeService::timer->getTickInterval()) / 1000); while(TimeService::timeCount > 0); } } //----------------- End CPP File (TimeService.cpp)
When i remove the contents of all functions, including the constructor, the program works. The program always simulate whitout problems.