Thread: Class arrays

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    66

    Class arrays

    I have two classes. The .h files go something like this:

    Code:
    class ClassA {
    ...
    public:
    ClassA::ClassA();
    ClassA::ClassA(int x, char array1[], char array2[]);  <-- constructor which sets some private variables
    ...
    }
    Code:
    class ClassB {
    Private:
    ClassA classArr[];
    ...
    Public
    ClassB::readFile(string path);
    ...
    }
    inside readFile(string path) function this line causes the program to die and the IDE gives me no error, just crashes. I want to know what's wrong with this assignment.
    Code:
    classArr[i] = ClassA(anInt, aCharArr, aCharArr2);
    EDIT: Okay, so I guess the issue was that since I only defined the array in header file, I never gave it a size.
    Last edited by Furious5k; 01-16-2011 at 04:38 PM.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Ooh, we get to guess what's in all the dots! This is exciting.

    Probably i has gone out of bounds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  2. Replies: 7
    Last Post: 05-26-2005, 10:48 AM
  3. Replies: 1
    Last Post: 04-20-2003, 05:02 PM
  4. arrays as class names
    By Katle in forum C++ Programming
    Replies: 2
    Last Post: 11-25-2002, 03:58 PM
  5. Do you store store one off data arrays in a class?
    By blood.angel in forum C++ Programming
    Replies: 5
    Last Post: 06-24-2002, 12:05 PM