The "new" operator is not behaving as expected in my code. I am using TI Compiler v5.2.5 on CCSv6.1.2 in Linux(Ubuntu x64 14.04) with a Tiva TM4C123GH6PM over an Olimex XDS100v2 emulator.
This code works perfectly fine on the tiva:
class TestClass { public: TestClass() { value = 5; }; int value; private: }; int main(void) { TestClass tc; int test = tc.value; return 0; }
"value" is set to 5.
However changing it to use a pointer to the "TestClass" causes the constructor to not be called and "value" is never initialized.
class TestClass { public: TestClass() { value = 5; }; int value; private: }; TestClass *tc; int main(void) { tc = new TestClass; int test = tc->value; return 0; }
Here "value" is a random number, presumable the existing value at the location it references in memory.