Original Post
How do you create instances of an object dynamically on the stack? can you give an a code example
#include <new>// some memory block allocated on the stackchar globalMemoryOnStack[GLOBAL_MEMORY_SIZE];// some class - I left out declaration and definition.class A;void SomeFunc() { // use placement-new to allocate an object of type "A" dynamically on the stack A * a = new(globalMemoryOnStack) A; // use A and don't call "delete" on it! call the destructor explicitly instead: (*a).~A();}This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more