Thread: Creating uninitialized array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Ugly C Lover audinue's Avatar
    Join Date
    Jun 2008
    Location
    Indonesia
    Posts
    489

    Creating uninitialized array

    Code:
    void *heap[size * sizeof(T)];
    To access each element in array we could use:
    Code:
    T &operator [] (unsigned int index)
    {
      return *reinterpret_cast< T * >(heap + index *sizeof(T));
    }
    Is there another way to create heap allocated array without initialization?

    Code:
    MyClass myObjects[1024];
    The code above will call the MyClass' default constructor 1024 times!
    Last edited by audinue; 08-28-2009 at 11:50 AM.
    Just GET it OFF out my mind!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Creating array of structs
    By knirirr in forum C++ Programming
    Replies: 12
    Last Post: 06-18-2008, 08:30 AM
  3. Creating a menu that reads input via an array?
    By Nalif in forum C Programming
    Replies: 6
    Last Post: 09-29-2006, 09:21 PM
  4. Array Program
    By emmx in forum C Programming
    Replies: 3
    Last Post: 08-31-2003, 12:44 AM
  5. Creating an array of object pointers
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2001, 10:01 PM