No appropriate default constructor available

Hi,

First I wrote a Binary-tree class to draw a binary tree on the window. The nodes were small circles. Then I become wanted to change the shape of the nodes from circles to triangles by another class, Binary-tree-derived which is derived from Binary-tree class.
I wrote the below code to do the job but I get two errors about constructors.
First, code:

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* The binary-tree class, one of the topics that has been said in Programming Principles and Practice using C++ book by Biarne Stroustrup.
   This code is written by R Abbasi (s.rabbasi@yahoo.com) */
#include <Simple_window.h>
#include <iostream>

Vector_ref<Line> vl;
Vector_ref<Circle> vc;
vector<Point> vp;
int pow(int);

class Binary_tree: public Shape {
public:
	Binary_tree(Point _p, int l){
		initialize(_p, l);
		preparing(); }

	void initialize(Point, int);
	void preparing();
	virtual void put_nodes(Point);
	void wheel(Point);
	void make_nodes(Point);
	void draw_lines() const {
		for(int i = 0; i*2+2 < vp.size(); i++) {
			fl_line(vp[i].x,vp[i].y,  vp[i*2+1].x,vp[i*2+1].y);
			fl_line(vp[i].x,vp[i].y,  vp[i*2+2].x,vp[i*2+2].y);
		}
	}

private:
	Point p;
	int i, j, k, level;
	double scale;
};
//**********************************
void Binary_tree::initialize(Point _p, int l) {
	p = _p;
	level = l;
}

//************************************

void Binary_tree::preparing() {
	if(level < 1) error("Bad inputted level!");
	else if (level == 1) put_nodes(p);
	else {
		scale = 5 * pow(level); 
		i = 1; j = 1; k = 3; 
		put_nodes(p); 
		make_nodes(p);
	}
}

//***************************************

void Binary_tree::put_nodes(Point p) { 
	vc.push_back(new Circle(p,5)); 
}

//******************************************

void Binary_tree::wheel(Point p) {
	put_nodes(Point(p.x - scale, p.y+30));
	put_nodes(Point(p.x + scale, p.y+30));
}

//*****************************************

void Binary_tree::make_nodes(Point p) {
	while(vp.size() < (pow(k)-1))
		wheel(vp[vp.size()-i++]);

	if(i < pow(level)) {
		k++;
		scale *= 1.0/2.0;
		make_nodes(vp[vp.size()-i]);
	}
}

//*********************

int pow(int l)  {
	int m = 2; 
	for(int k = 2; k < l; k++) m *= 2; 
	return m;
}

//***************************************

class Binary_tree_derived:public Binary_tree {
public:
	  Binary_tree_derived(Point _p, int l) {
		initialize(_p, l);
		preparing(); }
	void put_nodes(Point);
};
	
//***************************************

void Binary_tree_derived::put_nodes(Point p) { 
	vp.push_back(p);
	vl.push_back(new Line (Point(p.x-6,p.y), Point(p.x,p.y-6)));
	vl.push_back(new Line (Point(p.x,p.y-6), Point(p.x+6,p.y)));
	vl.push_back(new Line (Point(p.x+6,p.y), Point(p.x-6,p.y)));
}


//*******************

int main() try
{
	Simple_window win(Point(),1300,500, "Binary_tree");
	int level;
	cout<< "Please enter the level of the Binary-tree:";
	if(!(cin>>level)) error("Bad number of level!");

	Point p(10*pow(level),20);
	Binary_tree_derived btd(p,level);

	for(int i=0; i<3; i++) {
		vl[i].set_color(Color::red);
		win.attach(vl[i]);
	}
	for(int i=3; i<vl.size(); i++) {
		vl[i].set_color(Color::blue);
		win.attach(vl[i]);
	}
	win.attach(btd);
	win.wait_for_button();
	return 0;
}

//*****************************

catch(exception& e) {
	cerr << e.what() << "\n\a";
	return 0;
}


Errors are:

Error 12 error C2512: 'Binary_tree' : no appropriate default constructor available c:\users\cs\documents\visual studio 2012\projects\test_1\test_1\test_1.cpp 91

13 IntelliSense: no default constructor exists for class "Binary_tree" c:\Users\CS\Documents\Visual Studio 2012\Projects\test_1\test_1\test_1.cpp 91

My questions are:

1- Why I get those errors please?
2- And how to solve them please?

PS: This is an exercise. The exercise no. 12 of here: http://books.google.com/books?id=We21AwAAQBAJ&lpg=PP1&dq=programming%20principle%20and%20practice&pg=PA517#v=onepage&q&f=true



Binary_tree_derived derives from Binary_tree. Each time when Binary_tree_derived instance is created Binary_tree constructor will be called. If you do not tell to use other constructor, it will use default one, which is not present in Binary_tree class.

Just call base classs constructor explicitely:
Binary_tree_derived(Point _p, int l) : Binary_tree(_p, l) {}
So generally, each time when a derived class is created its base class' constructor is also called, yes?
Yes, because derived class contains base class inside and that base class needs to be constructed too.
Thank you very much for those great guidance.
Topic archived. No new replies allowed.