I am creating a DLL using the code provided to us by my instructor. However I have tried to compile it at home and it does not seem to work. Any help would be appreciated.
template<class T>
class mySTLlist : public list<T> {
public:
void addInMiddle(T t){}
friend ostream& operator<<(ostream& out, mySTLlist<T>& lst) {
for(mySTLlist<T>::iterator i = lst.begin(); i != lst.end(); i++)
out << *i << ' ';
out << '\n';
return out;
};
It gives me an Error at:
mySTLlist<T>::iterator i = lst.begin();
It says that i need a ; before it and it is not declared.
I am relatively new to C++
This is a good illustration of why it is important to include a complete example, and also to read all of the error messages. Your code is missing some include headers; at minimum, it needs the following at the top:
When I correct those and add the missing
}at the end, and compile it, I get three errors:The first one says that we need to add “typename” (note that this is in quotes, meaning the literal keyword
typename, not the name of a type), so we add exactly what it says we need, changing that line to:That fixes the problem. The error that you are seeing is a follow-on error — because the declaration of
iwas buggy, it skipped over it to see what it could do with the rest of the file. The next time you usei, it complains that it hasn’t been declared (which is, of course, because it skipped the declaration) — and, likewise, the missing;error is because of how it’s skipping past that first error. So, fix the first problem, and that fixes the rest.