J
John
Hi:
I want all objects of a class share the same set of data, which will
be input from a file when the code start to run. In my design, I use
static data member.
The definition of the class is as below:
class myclass{
public:
static int data[100]; //The shared data.
ifstream infile( "datafile.txt", ios::in );
int i = 0;
while ( infile >> data ) ++i; //Input data from the file.
//Definition of other data member and member functions.
void funct1();
void funct2();
char name[10];
protected:
.....
}
When the code runs, the data will be read in from the file. The
following objects:
myclass *c_1 = new myclass;
myclass *c_2 = new myclass;
.....
myclass *c_100 = new myclass;
c_1, c_2,..., c_100 share the same data.
Will my design work? If possible, please give me your suggestion.
By the way, this is not a homework question. I am working on a
project and considering how to share data.
Thanks a lot.
John
I want all objects of a class share the same set of data, which will
be input from a file when the code start to run. In my design, I use
static data member.
The definition of the class is as below:
class myclass{
public:
static int data[100]; //The shared data.
ifstream infile( "datafile.txt", ios::in );
int i = 0;
while ( infile >> data ) ++i; //Input data from the file.
//Definition of other data member and member functions.
void funct1();
void funct2();
char name[10];
protected:
.....
}
When the code runs, the data will be read in from the file. The
following objects:
myclass *c_1 = new myclass;
myclass *c_2 = new myclass;
.....
myclass *c_100 = new myclass;
c_1, c_2,..., c_100 share the same data.
Will my design work? If possible, please give me your suggestion.
By the way, this is not a homework question. I am working on a
project and considering how to share data.
Thanks a lot.
John