下面的類是本:插入對象插入集失敗
class Actor {
public:
float xpos{0};
float ypos{0};
Actor(float x, float y);
~Actor();
};
在管理類的靜態函數,我想創建這樣的演員,將其插入一組:
class ActorManager {
private:
ActorManager();
static std::set<Actor> actors;
public:
static void addActor(float x, float y);
}
定義:
std::set<Actor> ActorManager::actors = std::set<Actor>();
void ActorManager::addActor(float x, float y) {
Actor actor(x, y);
actors.insert(actor); // <--
}
隨着標線目前actors.insert
,編譯失敗。錯誤狀態:
/usr/lib/c++/v1/__functional_base:56:21: Invalid operands to binary expression ('const Actor' and 'const Actor')
我在這裏錯過了什麼?
你不會錯過任何的正確途徑。你在'actions = std :: Set()'的末尾有一個無關的'()'。 –
kfsone
似乎需要初始化靜態成員,如果我使用'{}',則會出現錯誤或者將它們排除。 – Appleshell