dynamic arrays in class's???

This is a discussion on dynamic arrays in class's??? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to figure this out with no luck so far. How do I dynamically allocate a character array within ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    dynamic arrays in class's???

    I'm trying to figure this out with no luck so far. How do I dynamically allocate a character array within a class? Do I have to set a pointer in the private secion and then link to that pointer from the constructors? Any advice would be great, a quick sample code would be even better. Thanks for the help in advance.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,544
    Sure, just put your char* pointer in the private area of your class

    The constructor then does
    myCharPointer = new char[howmany];

    The destructor does
    delete [] myCharPointer;

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    45
    alright, thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 01-01-2008, 03:07 PM
  2. processing dynamic arrays
    By Mario F. in forum C++ Programming
    Replies: 9
    Last Post: 06-04-2006, 11:32 AM
  3. Dynamic (Numeric) Arrays
    By DavidB in forum C++ Programming
    Replies: 5
    Last Post: 05-03-2006, 07:34 PM
  4. dynamic arrays and structures
    By godofbabel in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2002, 03:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21