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()’
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>
usingnamespace std;
class tree
{
tree * bottom;
tree * right;
string name;
public:
tree(string name);
};
class filer
{
string path;
tree rnode;
public:
filer(string path);
};
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.