|
|
#1 |
|
Guru
Join Date: Jan 2008
Location: U.S.
Posts: 7,824
|
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. Header file A.h Code:
class A
{
Private:
int rows;
int columns;
int array1[];
Public:
void build();
};
Code:
#include "A.h"
class B
{
Private:
int m;
int array2[];
A variable;
Public:
void test();
};
Code:
#include "A.h"
#include "B.h"
#include <iostream>
using namespace std;
int main()
{
int i[];
//random stuff here
return 0;
}
|
|
|
|
|
|
#2 |
|
Guru
Join Date: Jan 2008
Location: U.S.
Posts: 7,824
|
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; |
|
|
|
|
|
#3 | |
|
Fully Optimized
|
Quote:
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; Code:
x = new int[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" Code:
A objectName; 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 Kein Alkohol ist auch keine Lösung! |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|