I wanted to set up a new embedded project using MicroC OS-II and use C++.
When I want to create an instance of a class using the new operator, my processor runs into an exception which seems to come from a failing malloc call in the new operator. This is an example that fails:
testC* test = new testC();
with testC being some class with an integer member variable. BTW, I am using Altera Nios 2.
After some research, I came to the conclusion that malloc is not compatible with the RTOS. Therefore my question: Is it possible to use C++ with uC/OS-II? Or is there a way to replace the malloc call in the new operator?
So far, I could not find any additional information about this.
Thank you very much for your help. Best, Roman
I found a solution to avoid the new operator while still maintaining the polymorphism (which is the actual reason for using a new
operator). I create an object on the stack (or somewhere else), e.g. with
TestC test = TestC();
and in the actual code, I reference to the base class:
BaseC * base = &test;
Maybe this helps somebody else. Thanks everybody.