LessonInterface
class ILesson
{
public:
virtual void PrintLessonName() = 0;
virtual ~ILesson() {}
};
stl container
typedef list<ILesson> TLessonList;
calling code
for (TLessonList::const_iterator i = lessons.begin(); i != lessons.end(); i++)
{
i->PrintLessonName();
}
The error:
Description Resource Path Location Type
passing ‘const ILesson’ as ‘this’
argument of ‘virtual void
ILesson::PrintLessonName()’ discards
qualifiers
You can’t “put” objects of a class that has pure virtual functions(because you can’t instantiate it). Maybe you mean:
OK, as others pointed out, you have to make
PrintLessonNameaconstmember function. I would add that there is another small pitfall here.PrintLessonNamemust beconstin both thebaseand thederivedclasses, otherwise they will not have the same signature:To be honest, I find Jerry Coffin’s answer helpful for redesigning the printing functionality.