这可能是一个愚蠢的错误,但我收到以下错误:
error: request for member ‘speak’ in ‘it.__gnu_cxx::__normal_iterator<_Iterator, _Container>::operator* [with _Iterator = Bird* const*, _Container = std::vector<Bird*>, __gnu_cxx::__normal_iterator<_Iterator, _Container>::reference = Bird* const&]()’, which is of non-class type ‘Bird* const’
导致错误的代码是:
void Aviary::speakAll(std::ostream &os) const{
for(std::vector<Bird*>::const_iterator it = birds.begin(); it != birds.end(); it++){
it->speak(os);
}
}
我用来存储 Bird 指针的结构是:
typedef std::vector<Bird*> Birds;
void Aviary::addBird(Bird *bird){
if(!bird) throw std::logic_error("");
birds.push_back(bird);
}
问题是如何从指针调用对象成员函数?