Thread: dynamic arrays in class's???

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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, 04: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