I am a totally novice programmer. I want to define a dynamic array within a class (index is a pointer to the dynamic array I want to define). The code I use follows. My program crashes when run.
The question I have is if it is at all possible to use dynamice arrays within a class, if yes, I am on the right track? and again if I am not on the right track, what is an appropriate method to do that?
I appreciate any help.
in the meanwhile, don't hesitate to ask if you need further details.
Thank you all,
#include <iostream>
using namespace std;
class NODE
{
public:
int * index;
NODE (int dim)
{
int * index = new int [dim];
};
};
int main()
{
NODE sampleNode(5);
sampleNode.index[0]=1;
cout << sampleNode.index[0];
return 0;
}
This post has been edited by machoolah: 27 May 2009 - 04:54 PM

New Topic/Question
Reply




MultiQuote







|