c++ - non-scalar type requested -


Someone can help me with error

  `non-scale ' Type 'B' is requested  

I have class A and it has been received from B, but I have problems with these lines:

 < Code> A (1); A * PB = new B (A); Bb = * pb; // Here I have an error  

Thanks for any help

  class A {protected: int player; Public: A (int initPlayer = 0); A (Consta and;); & Amp; Operator = (Constant & amp; amp;;); Virtual ~ A () {}; Virtual void foo (); Zero foo () const; Operator int (); }; Class B: Public A {Public: B (Intimate): A (Entplayer) {}; ~ B () {}; Virtual void foo (); };  

edit

I have this code and (I can not change it):

  A (1); A * PB = new B (A); Bb = * pb;  

I tried to make constructor for B:

B :: B (Constant & amp; A): Player (a.player) {} B & amp; ; B :: operator = (Constant A & A) {If (this == & amp; A) {return * it; } Player = a.player; Return * This; }

But this gives me an error, really needs help from professionals

Your problem is due to fixed type testing when you have this line:

  A * PB = new B (A);  

pb is a * of the constant code and its dynamic type is B * . The dynamic type is correct, the compiler is checking the static type.

For this simple code, when you know that the dynamic type of pb is always B, you can fix it with a fixed artist:

  b b = * static_cast & lt; B * & gt; (Pb);  

But be warned that if the dynamic type of pb was a A * , then the reason for compulsive behavior would be the reason.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -