How to initialize pointer char array?

Hi,

I got a class that has a pointer and i'm trying to initialize the values but for some reason im getting overload function errors.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

Records::Records ( string name, int size, double q[], double a[])
{

        studentName = name;
	weeks = size;
	quiz = new q[];
	assignment = new a[];

}

class Records
{
private:
    string  studentName;
    double *quiz;
	double *assignment;
	int weeks;

public:
	void load(ifstream& inf); 
	void store(ofstream& of);
	Records ();
        ~Records ();

};

int main()
{

	Records person [1] = { Records("Me" , 2 , 4 ,5)};



  ofstream myfile;
  myfile.open("Records.dat", ios::binary | ios::out);
  Records.store(myfile);
  myfile.close();
  return(0); 


}
On lines 7 and 8 you are not allocating memory correctly. You cannot say
1
2
quiz = new q[];
assignment = new a[];

What data type is "q" and "a".
A recommendation would be to pass in an integer instead of an array and then allocate an array using the integers, such as:
1
2
quiz = new double[q];
assignment = new double[a];

Just make sure you deallocate those variables in your destructor or else you will get memory leaks.
Topic archived. No new replies allowed.