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;
}
};
问题:我想使用继承的类作为map值
地图是:
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
(&)())'
我该如何解决?
最佳答案
CommercialRadio new_station();
声明一个不带参数且返回new_station
的函数CommercialRadio
。删除括号。 C ++语言的此属性称为most vexing parse。
此外,您的基类没有定义虚拟析构函数几乎是不正确的。
关于c++ - 使用继承的类作为map值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14527146/