[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppMalloc
Prefer using new as std::malloc does not call a constructor. The code below demonstrates this using the Gossip class.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppMalloc
(C++) std::malloc
C-style way of allocating memory. You can free this memory using std::free.Prefer using new as std::malloc does not call a constructor. The code below demonstrates this using the Gossip class.
class Gossip { public: Gossip() { std::cout << "Constructor" << std::endl; } ~Gossip() { std::cout << "Destructor" << std::endl; } void init() { std::cout << "Initialization" << std::endl; } }; int main() { Gossip * g = (Gossip*) std::malloc(sizeof(Gossip)); //Dirty C cast to Gossip* g->init(); std::free(g); }
- include <iostream>
- include <cstdlib>
'malloc' links
Code links
- cout
- cstdlib (header file)
- endl
- free
- include
- int
- iostream (header file)
- main
- std
- std::cout
- std::endl
- std::free
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
