Class 在类';s

Class 在类';s,class,stl,constructor,destructor,superclass,Class,Stl,Constructor,Destructor,Superclass,以下是我当前代码的3部分。当我尝试遍历向量并取消对“compare”方法的引用时,main.cpp文件中出现错误。有人能帮我找出这个错误的原因吗 Main.cpp: #include <iostream> #include <vector> #include "Scores.h" using namespace std; int main() { vector<comparable*> comparables; for(int i = 0

以下是我当前代码的3部分。当我尝试遍历向量并取消对“compare”方法的引用时,main.cpp文件中出现错误。有人能帮我找出这个错误的原因吗

Main.cpp:

#include <iostream>
#include <vector>
#include "Scores.h"

using namespace std;

int main()
{
    vector<comparable*> comparables;

    for(int i = 0; i < 5; i++)
    {
        comparables.push_back(new Player());
    }

    for(vector<comparable*>::iterator itr = comparables.begin(), end = comparables.end(); itr != end ; itr++ )
    {
        (itr*)->compare(); ****THIS IS THE LINE WHERE THE ERROR OCCURS****************
    }

    cout << "Mission Accomplished!\n\n";

    return 0;
}
换一个怎么样

for(vector<comparable*>::iterator itr = comparables.begin(), end = comparables.end(); itr != end ; itr++ )
{
    (itr*)->compare(); ****THIS IS THE LINE WHERE THE ERROR OCCURS****************
}
for(vector::iterator itr=compariables.begin(),end=compariables.end();itr!=end;itr++)
{
(itr*)->compare();****这是发生错误的行****************
}

for(vector::iterator itr=compariables.begin(),end=compariables.end();itr!=end;itr++)
{
(*itr)->compare();//这是以前发生错误的行:)
}

我们需要查看错误消息的实际文本以了解发生了什么。我忘记了每个类XD后面的“;”,woops,但这似乎解决了这个问题,但现在我有了另一个问题。当我试图遍历我的向量时。@anjruu o sry我忘了在btw-1中添加它。如果有什么你没有问的,应该从问题中删除@是的!!!非常感谢你=有趣的是,它总是简单的东西
#ifndef SCORES_H_INCLUDED
#define SCORES_H_INCLUDED

class comparable
{
    public:

    virtual void compare() = 0;

};

class Player: public comparable
{
    public:

    Player();
    void compare();
    void getscore();
    void getname();

    private:
    std::string player_name;
    int player_score;
};


#endif // SCORES_H_INCLUDED
for(vector<comparable*>::iterator itr = comparables.begin(), end = comparables.end(); itr != end ; itr++ )
{
    (itr*)->compare(); ****THIS IS THE LINE WHERE THE ERROR OCCURS****************
}
for(vector<comparable*>::iterator itr = comparables.begin(), end = comparables.end(); itr != end ; itr++ )
{
    (*itr)->compare(); // THIS WAS THE LINE WHERE THE ERROR USED TO OCCUR :)
}