Thread: Quick question about memory allocation

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Araanor View Post
    You know, I thought I asked if it would work. Does the cast produce undefined behaviour?
    The thing is, that while it may work, it's not really C++ -- it's more like C. If you're going to have type safety, then why not use it? There's no need to use void in C++, since we have templates. Just use T and allocate that with new.
    I don't really see why not? There's absolutely no reason (unless you're storing lots of different objects inside one container, in which case you need to be careful) not to.
    I tried to do that once. It wasn't very flexible and you'll have to be able to remember the type or the user of the class has to cast it once it gets its pointer.
    In either case, it is to be avoided, if possible.

    So do answer, because I'm not really sure. Are you storing multiple objects in one container or just one?
    Last edited by Elysia; 11-19-2007 at 12:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mutex and Shared Memory Segment Questions.
    By MadDog in forum Linux Programming
    Replies: 14
    Last Post: 06-20-2010, 04:04 AM
  2. POSIX Threads and dynamic memory allocation
    By PING in forum Linux Programming
    Replies: 1
    Last Post: 04-02-2009, 10:28 AM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  4. Memory allocation at runtime?
    By electrolove in forum C Programming
    Replies: 6
    Last Post: 02-05-2003, 11:39 AM
  5. Yet another memory question
    By Dohojar in forum C Programming
    Replies: 5
    Last Post: 03-16-2002, 01:47 PM