tree problem

I have 2 file named first.cpp and first.h and a main. When i compile my main get these errors:
first.cpp: In constructor ‘filer::filer(std::string, std::string)’:
first.cpp: error: no matching function for call to ‘tree::tree()’

first.h: note: candidates are: tree::tree(std::string, std::string, std::string)
first.h: note: tree::tree(const tree&)

I could not get rid of this problem. I'm sure that is no error about including and compiling but i don't know. These are my files;

"first.h" is;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string>
using namespace std;
class tree 
{
	tree * bottom;
	tree * right;
	string name;
public:
	tree(string name);
};

class filer 
{
	string path;
	tree rnode;
public:
	filer(string path);
};


"first.cpp";
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
#include "first.h"
using namespace std;

filer::filer(string path){
	//tree("xyz");
}



You are not calling the tree constructor in filer constructor
eg:
1
2
3
filer::filer(string path) : tree("xyz")
{
}
Actually, wrote tree constructor in first.cpp. But the situation did not change, whether i call the constructor or not, i get same error.
I think you misunderstood Bazzy.

1
2
3
4
filer::filer(string path){
    tree("xyz");  // this does not call the tree ctor for 'this'
     // instead it creates a seperate 'tree' object.
}


Because 'tree' has no default ctor, you need to call one explicitly. This has to be done in the initialization list of the 'filer' ctor, as per Bazzy's example. You can't put the ctor in the body of the function.
But when i do it, it gives me same errors. no change.
From the last part of code you posted, I thought 'tree' was a member. The member name is 'rnode', so use filer::filer(string path) : rnode("xyz") .
Thanks, that completely solved my problem.
Topic archived. No new replies allowed.