0
class StationSongs {
protected:
    int original_song; 
};

class NewsRadio: public StationSongs {
public:
    NewsRadio()
    {
        current_song = NULL;
        currently_empty = 0;
        original_song = 0;
        start_time_of_song = 0;
        next_song_to_play = NULL;
    }
};

class CommercialRadio : public StationSongs {
public:
    CommercialRadio() {
        current_song = NULL;
        currently_empty = 0;
        original_song = 0;
        start_time_of_song = 0;
        next_song_to_play = NULL;
    }
};

問題: 継承されたクラスをマップ値として使用したい

マップは次のとおりです。

typedef MtmMap<double, StationSongs*> RadioMap;


method{

    CommercialRadio new_station();

    RadioPair new_pair(stationFrequency,*new_station);

    radio.insert(new_pair);
}

このエラーが発生します:

Multiple markers at this line

- no matching function for call to 'mtm::MtmMap<double, mtm::StationSongs*>::Pair::Pair(double&, 

mtm::CommercialRadio 
     (&)())'

どうすればこれを解決できますか???

4

1 に答える 1

1

CommercialRadio new_station();new_station引数を取らず、 を返す関数を宣言しますCommercialRadio。括弧を削除します。C++ 言語のこの特性は、最も厄介な parseとして知られています。

さらに、基本クラスが仮想デストラクタを定義していないというのは、ほぼ間違いなく正しくありません。

于 2013-01-25T21:10:31.170 に答える