Class members of type bool are automatically initialized

Hello,

Can anybody please tell me why bool-type members of a class are automatically initialized to 'true'?

For example, for the class Point defined as following:
1
2
3
4
5
6
7
8
9
10
11
class Point
{
private:
	int x;
	int y;
	bool b;
public:
	Point(){}
	~Point(){}
	inline Point(int x,int y){this->x=x;this->y=y;}	
};

if I call the constructor: Point p(1,1), the member b is set to 'true'.

Thank you in advance for your help.
This is just not true. It's a coincidence. The value is completely a garbage value. I personally had it initialised to false yesterday with an OpenGL program. It's just a coincidence!!

Why is this annoying you? just include it in your constructor and initialise it!!!

1
2
3
4
5
6
7
8
9
10
11
class Point
{
private:
	int x;
	int y;
	bool b;
public:
	Point(){b = 0;}
	~Point(){}
	inline Point(int x,int y){this->x=x;this->y=y;}	
};
Last edited on
Hi, TheDestroyer. I actually have no problem with that, just by coincidence 'discovered' that after some tests. It is clear now. Thanks.
Topic archived. No new replies allowed.