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++ 语言的这个特性被称为最令人头疼的解析

此外,您的基类没有定义虚拟析构函数几乎肯定是不正确的。

于 2013-01-25T21:10:31.170 回答