non-scalar type requested

Posted by lego69 on Stack Overflow See other posts from Stack Overflow or by lego69
Published on 2010-06-15T15:10:06Z Indexed on 2010/06/15 15:12 UTC
Read the original article Hit count: 207

Filed under:

can somebody please help me with an error

conversion from `A' to non-scalar type `B' requested

I have class A and derived from it B, but I have problems with these rows:

A a(1);
A *pb = new B(a);
B b = *pb;    //here I have an error

thanks in advance for any help

class A {
protected:
    int player;
public:
    A(int initPlayer = 0);
    A(const A&);
    A& operator=(const A&);
    virtual ~A(){};
    virtual void foo();
    void foo() const;
    operator int();
};

class B: public A {
public:
    B(int initPlayer): A(initPlayer){};
    ~B(){};
    virtual void foo();
};

© Stack Overflow or respective owner

Related posts about c++