A
Allen Maki
/*
I am new to OOP. I have problem in including an array in a class.
I would like to know why the following codes can be built
but can not be compiled. Thanks.
*/
#include <iostream>
using namespace std;
class Array
{
public:
int *item;
int capacity;
};
int main()
{
Array *Jan;
Jan = new Array;
Jan->capacity = 5;
for (int i =0; i<5; i++)
Jan->item = i;
for(i =0; i<5; i++)
cout << Jan->item << endl;
return 0;
}
I am new to OOP. I have problem in including an array in a class.
I would like to know why the following codes can be built
but can not be compiled. Thanks.
*/
#include <iostream>
using namespace std;
class Array
{
public:
int *item;
int capacity;
};
int main()
{
Array *Jan;
Jan = new Array;
Jan->capacity = 5;
for (int i =0; i<5; i++)
Jan->item = i;
for(i =0; i<5; i++)
cout << Jan->item << endl;
return 0;
}