I am making a program in which I am inheriting publicly my Set class from a built-in STL container class set. I have to use the iterator type, while making some other specialized functions for my own Set class, as defined in the stl set class.
Now my question is: What would be the syntax to declare variables of iterator type inside my member functions? I have been trying:
template<typename T>
class Set : public set<T> {
public:
bool func()
{
iterator it,it2;
}
};
But the compiler is not recognizing iterator type. Kindly tell me the syntax to use the iterator type from the stl set class.
The compiler complains because it doesn’t know that
iteratoris in fact a member ofset<T>.set<T>is what’s called a dependent type, because it depends on the type parameterT. In a nutshell, the compiler does not look inside dependent names when resolving types.This FAQ entry is relevant to this question. Also, be sure to read through the answers to this Stack Overflow question. To fix it, use
typename.But really, you should be using composition instead of inheritnace for this case, like this: