We're basically just making an implementation file for a double linked list. We were given a header file with all of the functions to implement, and all we have to do is write the implementation file. Most of it is very easy, and I'm fairly sure that I have a good understanding of the concept itself, as well as how to write most of the functions.
Where I'm running into a problem however is with the nested class iterator. Basically, the initial declaration is something like this in the header file:
namespace name
{
template < typename T>
class List
{
public:
class const_iterator
{
public:
const_iterator();
const_iterator & operator++();
...
}
}
}
So when writing the implementation file, I did the constructor like the following:
template <typename T>
name::List<T>::const_iterator::const_iterator() : current( NULL )
{}
And I can do that for all of the functions unless their is a better way ( I wish I could just do all this code inline, and wouldn't have an issue, but we're unable to modify the header file, and can only touch the .cpp implementation file ), but with the second function ( there are others, but these 2 serve the purpose of examples to show my issue ), I'm unsure how to write the first line of the operator++ function, because it returns a nested object, and I get an error similar to the following when I try:
list.cpp(14) : error C2143: syntax error : missing ';' before 'name::List<T>::const_iterator::++'
I've tried versions such as:
const_iterator name::List<T>::const_iterator::operator++() or name::List<T>::const_iterator & name::List<T>::const_iterator::operator++()
But to be honest I have no experience with nested classes and am unsure quite how to implement returning an object of a nested class in an implementation file.

New Topic/Question
Reply
MultiQuote







|