1

我正在尝试创建一个函数,该函数接受参数为 sf::Shape 对象(以便仅接受圆、矩形等)但由于它是一个抽象类,它向我抛出错误“抽象类类型 sf 的参数: :不允许形状"

这是我的功能的签名: GraphObject::GraphObject(sf::Shape shape, int z = 0)

是否有另一种方法将形状作为参数传递?谢谢

4

1 回答 1

2

Accept shape as a reference or a pointer: GraphObject::GraphObject(sf::Shape& shape, int z = 0) or GraphObject::GraphObject(sf::Shape* shape, int z = 0).

The reasoning is pretty self-explanatory. You cannot have objects of an abstract class type - well because they are abstract.

于 2021-01-09T17:08:24.510 回答