I am more a C guy but I am currently working on a C++ project. That is why i am getting a little confused:
we have an inheritance like this:
Node->MultiNode->RoundAbout
Now some code(for simplicity, I ommitted almost all but the constructors):
class MultiNode : public sim_mob::Node {
public:
MultiNode(int x, int y) : Node(x, y) {}
...
}
and
class Roundabout : public sim_mob::MultiNode {
public:
Roundabout() : MultiNode() {}
}
As you can see, the Roundabout() constructor calls MultiNode() constructor without any argument while MultiNode has only one constructor with 2 args :
MultiNode(int x, int y)
Is such a scenario possible? what is the expanation please?
This code compiles well in its original place but when I copied the folder to a testing area to start editing, I get this error(which is sensible to me):
error: no matching function for call to ‘sim_mob::MultiNode::MultiNode()
there is no other similar file or class to suspect misplacing.
error for your reference:
~/workspace/parser5/geospatial$ make
Scanning dependencies of target driver
[ 33%] Building CXX object CMakeFiles/driver.dir/geo5-pskel.cxx.o
In file included from /home/vahid/workspace/parser5/geospatial/geo5-pskel.hxx:134:0,
from /home/vahid/workspace/parser5/geospatial/geo5-pskel.cxx:39:
/home/vahid/workspace/parser5/geospatial/Roundabout.hpp: In constructor ‘sim_mob::Roundabout::Roundabout()’:
/home/vahid/workspace/parser5/geospatial/Roundabout.hpp:34:27: **error: no matching function for call to ‘sim_mob::MultiNode::MultiNode()’**
/home/vahid/workspace/parser5/geospatial/Roundabout.hpp:34:27: note: candidates are:
/home/vahid/workspace/parser5/geospatial/MultiNode.hpp:42:2: note: sim_mob::MultiNode::MultiNode(int, int)
/home/vahid/workspace/parser5/geospatial/MultiNode.hpp:42:2: note: candidate expects 2 arguments, 0 provided
/home/vahid/workspace/parser5/geospatial/MultiNode.hpp:40:7: note: sim_mob::MultiNode::MultiNode(const sim_mob::MultiNode&)
/home/vahid/workspace/parser5/geospatial/MultiNode.hpp:40:7: note: candidate expects 1 argument, 0 provided
make[2]: *** [CMakeFiles/driver.dir/geo5-pskel.cxx.o] Error 1
make[1]: *** [CMakeFiles/driver.dir/all] Error 2
make: *** [all] Error 2
thank you
No, you cant do that because no default constructor is available for MultiNode. create a default constructor also that accepts no arguments or provide some default arguments to MultiNode Constructor.
i.e.
or