Problem with class declaration

Hi! I am using VS 2013. I have a problem with class. The compiler says:
Error C2079: 'arr' uses undefined class 'Array'. How to fix it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;
void test(void);

int main(void)
{
	test();
	return 0;
}

void test(void)
{
	Array arr;
	arr.Count = 5;
	cout << "count = " << arr.GetVolume() << endl;
}
class Array
{
public:
	int Count;
	double GetVolume();
};
double Array::GetVolume()
{
	return pow(13, 4);
}
Put the definition before the use, so that at the point of use, the class is defined.
Thanks for answer, but I don't understand what you mean.
The compiler reads one line at a time.

When on line 7, it remembers that it saw declaration of "test" on line 3 and that the use matches the declaration.

When on line 13 there is word "Array", but no such name has occurred in the file yet. Only after line 22 does the compiler know what "Array" means.
But isn't there class prototyping for class like for functions (e.g. "test" function)?
Yes, there is forward declaration. You could write class Array; to tell that word Array is a name of a type.

However, on line 13 the compiler has to reserve memory for "arr". How many bytes does an Array require? The definition (lines 17--22) tells that and therefore it has to be before the point of use.
Now I get it. Thanks for explanation!
Topic archived. No new replies allowed.