cannot convert 'Book' to 'Node' in initialization
时间: 2023-08-21 20:03:47 浏览: 108
This error occurs because you are trying to convert an object of type `Book` to an object of type `Node` during initialization. The compiler is indicating that this conversion is not possible.
To resolve this issue, you need to ensure that the types are compatible for the initialization. If `Book` is a subclass of `Node`, you can perform an upcasting to convert the `Book` object to a `Node` object.
Here is an example:
```cpp
class Node {
// ...
};
class Book : public Node {
// ...
};
Book book;
Node node = static_cast<Node>(book); // upcasting
```
In this example, the `Book` class is derived from the `Node` class. By using the `static_cast` operator, you can safely convert the `Book` object `book` to a `Node` object `node`.
Please note that this approach assumes that the `Book` class is indeed a subclass of the `Node` class. If they are unrelated or the inheritance relationship is not established correctly, you may need to reconsider your design or provide more context for further assistance.
阅读全文