Class question

I am trying to set up a class to hold individual runs of data like this:

class TestRun
{
public:
TestRun();
TestRun(int);
~TestRun();
int MAXSIZE;
private:

double angle[500];
double torque[500];
double tension[500];
double reaction[500];
};

And another class that contains a vector of these testruns like this:

class TestSet
{
public:
TestSet();
~TestSet();
bool addRun(TestRun);
bool deleteRun(int);
int runCount();
protected:

private:
TestHeader TestInfo;
vector<TestRun> testRuns;
};

However I would like to define the size of the arrays inside testrun later instead of defining them as shown. Can someone tell me how to do that?

Thanks in advance for your help.
declare them as:
double *angle;

Allocate memory:
angle = new double[500]

free the memory
delete [] angle
Thanks Zaita.

I'm trying to create a class, TestSet, that contains a collection of another class, TestRun. In the test program an instance of the first class is made ok and then added to a vector in the other class. But as this program is ending it crashes inside the destructor of the class TestSet.

Can someone please tell me what I'm doing wrong?

Test progam:
1
2
3
4
5
6
7
8
int main()
{
    TestRun tst(500);
    TestSet currTest;
    if (currTest.addRun(tst))
        cout << "\ntest added successfully\n";
    return 0;
}


This is from the header file:
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
class TestHeader
{
	public:
	    TestHeader();
	    ~TestHeader();
	protected:
            vector<string> headerData;
	private:
};


class TestRun
{
    public:
        TestRun();
        TestRun(int);
        ~TestRun();
    private:
	double *angle;
        double *torque;
        double *tension;
        double *reaction;
};

class TestSet
{
	public:
		TestSet();
		~TestSet();
		bool addRun(TestRun);
		bool deleteRun();
		int runCount();
    protected:

    private:
        TestHeader TestInfo;
        vector<TestRun> testRuns;
};


This is from the implementation :
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
TestHeader::TestHeader()
{
    cout << "TestHeader constructor\n";
    headerData.push_back("one");
    headerData.push_back("two");
    headerData.push_back("three");
}

TestHeader::~TestHeader()
{
    cout << "TestHeader destructor\n";
}

TestRun::TestRun()
{
    angle = new double[500];
    torque = new double[500];
    tension = new double[500];
    reaction = new double[500];
    cout << "TestRun constructor\n";
}

TestRun::TestRun(int ms)
{
    angle = new double[ms];
    torque = new double[ms];
    tension = new double[ms];
    reaction = new double[ms];
    cout << "TestRun(int) constructor\n";
}
TestRun::~TestRun()
{
    delete [] angle;
    delete [] torque;
    delete [] tension;
    delete [] reaction;
    cout << "TestRun destructor\n";
}

bool TestSet::addRun(TestRun tr)
{
    testRuns.push_back(tr);
    return true;
}

bool TestSet::deleteRun()
{
    testRuns.pop_back();
    return true;
}
int TestSet::runCount()
{
    return static_cast<int>(testRuns.size());
}

TestSet::TestSet()
{
    cout << "TestSet constructor\n";
}

TestSet::~TestSet()
{
    cout << "TestSet destructor\n";
}
Topic archived. No new replies allowed.