c++ automatic 'type cast' conversion -
Can someone explain why the code is not compiled below error:
Error 1 error C2243: 'Type cast': Conversion from 'Fear *' to 'Base *' is present, but not inaccessible: \ user \ lzizva \ documents \ mta \ c ++ \ projects \ temp1 \ 17022014.cpp 50 1 temp1 Error 2 Error C2243: 'Type Cast': Conversion from 'Fear *' to 'Base *' is present, but not inaccessible: \ users \ lzizva \ documents \ mta \ c ++ \ projects \ temp1 \ 17022014 .cpp 51 1 temp1 3 IntelliSense: To insufficient Conversion base class "base" is not allowed d: \ users \ lzizva \ documents \ mta \ c ++ \ projects \ temp1 \ 17022014.cpp 50 12 temp1 4 IntelliSense: Conversion "base" in inaccessible base class d: \ Users I thought that when there is a personal heritage, the child gets all the qualities and methods and they are set in private form. And this should affect only the subclasses of the child, what do not I understand here? What does the compiler actually do? Thanks in advance, Liron #include & lt; Iostream & gt; using namespace std; Class Base {int n; Base * Next; Public: Base (Int N, Base * Next = Faucet): N (N), Next (Next) {} Virtual Zero Print () const {cout & lt; & Lt; N & lt; & Lt; Endl; If (next! = Null) {Next-> Print (); }} Virtual ~ base () {cout & lt; & Lt; "Base" & lt; & Lt; Endl; }}; Classroom: private base {int counter; Public: Der (Int N, Base * Next = Faucet): Base (N, Next), Counter (N) {} Zero Print () Const. {COT & LT; & Lt; Counter & lt; & Lt; Endl; Base :: Print (); } ~ Der () {cout & lt; & Lt; "Der" & lt; & Lt; Endl; }}; Zero main () (der a (1); Der two (2, and one); Der three (3, and 2); three.print ();}
The problem is in the construction of two
and three
: der
The constructor gets base *
, but you are passing Fear *
Points.
Because der
private Base
, der
-> base
is unavailable in the conversion main ()
, there are errors in this way. < / P>
Comments
Post a Comment