I have a simple java program that consist of 3 classes. Base, BaseBlock and Derived. The first 2 are abstract classes. Each class has it's corresponding interface. There is one more interface called BaseExtendedInterface which models the java feature of extending the interfaces had has the purpose of make a deep copy of the Derived classes ( in this case only one class). In order to do a deep copy i am using a copy constructor in the Derived class together with the method deepCopy(). The copy constructor needs to call his parent copy constructor until it reaches the Base class using super() . This is pretty standard constellation that can be found in many Java projects.
Since i started learning C++, in my experience the best thing to learn is just to try to write something, thus I am trying to convert those 3 classes to modern c++11 and CMAKE, since i have found that this is what the folks are using today. I spend a week just tyring out CMAKE to this result.I am facing 2 errors.
this one C++ Candidate constructor not viable: no known conversion and this one
Why am I getting "Candidate constructor not viable"?
but i still do not understand how to fix this. Please note that i am kind of beginner in c++.
In order to show the problem i have created two repositories on github one with the (java + maven) code and the second with the (c++ and CMAKE) project.
https://github.com/syncdonkey/simpleJavaConstelation
and
https://github.com/syncdonkey/simpleCPPConstelation
/Projects/main/Derived.cpp:21:11: note: candidate constructor not viable: no known conversion from 'std::shared_ptr<main::BaseBlock>' to 'unsigned int' for 1st argument
Derived::Derived(unsigned int localInt) : BaseBlock()
What is the problem with the Derived class here, i am just trying to call the constructor on the line 21, what has the "super" class to do with the converstion to Drived. As far as i understand the the empty BaseBlock constructor should be called first before the Derived class is constructed. But i am not trying to convert or cast here anything just trying to call the parent/super empty constructor
/Projects/main/Derived.cpp:16:11: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
Derived::Derived() : BaseBlock()
Where is this damn misery constructor argument coming from?
I would really appreciate an explanation, since i do want to learn C++. Many thanks in advanced. I am using clang as a compiler
Aucun commentaire:
Enregistrer un commentaire