I have a base class and a derived class. When i try to convert the derived class pointer to base class pointer, i get a compilation error.
class Base {
..
}
class Derived: public Base {
}
class X {
public:
Base* getWriter(int shard) {
return writers[0][shard];
}
private:
mutable vector<vector<Derived*>> writers_;
}
And the error I get is
error: cannot initialize return object of type 'Base *'
with an lvalue of type 'value_type' (aka 'Derived *') on line "return writers[0][shard];"
The header that defines X
is not including the header that defines class Derived
, so the compiler does not know the relationship between Base
and Derived
.
This error happens when the relation between the types Base and Derived are not known to the compiler.
This is the case if you only have forward declarations of Base and/or Derived, but no class definitions. Including the header that defines Derived before you attempt this conversion should resolve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With