Segmentation fault error message

i compile this code but it's crushed with segmentation fault error message.
i think there are problem in private class QList. How solve this problem and why it take place?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <QList>
class Carr
{
	public:
		Carr()		{val.append(1);};
		int get(int n)	{return val[n];};
	private:
		QList<int> val;
};
class Cbrr
{
	public:
		Cbrr()		{Carr* arr = new Carr();};
		int get(int n)	{return arr->get(n);};
	private:
		Carr* arr;
};
int main()
{
	Cbrr* brr = new Cbrr();
	int i=brr->get(0);
	return 0;
};

sorry for my bad english :)
Line 13 - the class Cbrr constructor. You are creating and initialising a new Carr pointer and NOT the one which is part of the class.
It should read:

Cbrr() {arr = new Carr();}; //initialise the correct pointer
thnx...
so noob mistake :/
Also, you might want to consider using better names.
I read that as
1
2
3
4
5
class Carr{
    Carr(){
        Carr *arr=new Carr();
    }
}

Which is totally messed up.
Topic archived. No new replies allowed.