Inheritance related errors

Hey guys, could someone point out to me what's wrong with my code. I've been looking at it for a while and I see no fault.


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
class animal {
public:
	animal() {
		cout << "An animal is in da house.\n";
	}
	virtual void Roar();
};

void animal::Roar() {
	cout << "*insert roar*\n";
}

class bear : public animal {
	bear() : animal() {
		cout << "A bear is in da air";
	}
	void Roar();
};

void bear::Roar() {
	cout << "GRRRRR!\n";
}

void letsRoar(animal * someAni) {
	someAni->Roar();
}

int main() {
	bear grizzly;

	animal * PointBearer = &grizzly;

	letsRoar(PointBearer);

	return 0;
}



Output from visual studio

	2	IntelliSense: "bear::bear()" (declared at line 21) is inaccessible	c:\Users\Cameron\Documents\Visual Studio 2013\Projects\JustForFun\JustForFun\Source.cpp	36	7	JustForFun



Error	1	error C2248: 'bear::bear' : cannot access private member declared in class 'bear'	c:\users\cameron\documents\visual studio 2013\projects\justforfun\justforfun\source.cpp	36	1	JustForFun

Last edited on
Ooops. Got it.

1
2
3
4
5
6
7
class bear : public animal {
public: // missing
	bear() : animal() {
		cout << "A bear is in da air";
	}
	void Roar();
};
You can't construct a bear because the constructor is private (which makes it inaccessible in main.)

Make it public.
Topic archived. No new replies allowed.