USING C++
I am trying to use a class inside another class. However, when I define the variable from the first class in the second I get an error saying, "Incomplete type". This is what my code looks like.

Now the problem is that the array array2 gives me errors saying incomplete type. If I delete A.h and not define "variable", then "i" gives me an error with incomplete type on main(). What's wrong here?

I have an update on this issue. Instead of using a class within another class, I'm trying to create a dynamic array using new/delete in a class function. However, I keep getting this incomplete type error. Am I supposed to declare the dynamic array in the header file definitions? I currently have it in the actual code for the function (which is located in the source file). The class definition header file is included in the source file. Do I need to make a second declaration of the form:

Code:

class A;

before int main() in my source file? By that I mean with all my #include's.

I have an update on this issue. Instead of using a class within another class, I'm trying to create a dynamic array using new/delete in a class function. However, I keep getting this incomplete type error. Am I supposed to declare the dynamic array in the header file definitions? I currently have it in the actual code for the function (which is located in the source file). The class definition header file is included in the source file. Do I need to make a second declaration of the form:

Code:

class A;

before int main() in my source file? By that I mean with all my #include's.

It's was a bit difficult following exactly what you were explaining so I'll try to answer what I think you asking.

In your header file you want to have a pointer declaration (unless of course it is only to be accessed by one particular function then you don't have to have it in your header). That is, if you want to create a dynamic array of ints use this:

Code:

int *x;

Then in your implementation file for the function you create a new array by using (for example):

Code:

x = new int[10];

which creates a dynamic array of size 10.

Ok, you probably already knew that but just making sure.

You only need to include (assuming in this case your header file is called A.h):

Code:

#include "A.h"

Then in your main() create a new object using:

Code:

A objectName;

to access your class members and functions.

edit - k, after reading again I don't think I answered any of your questions lol

__________________
Killing under the cloak of war is no different than murder