#pragma once
class iterator
{
public:
typedef std::forward_iterator_tag iterator_category;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;
iterator();
// Get the data element at this position
reference operator*() const;
pointer operator->() const;
// Move position forward 1 place
iterator& operator++();
iterator operator++(int);
// Comparison operators
bool operator== (const iterator&) const;
bool operator!= (const iterator&) const;
private:
};
I get the compile error complaining about line 6:
error C2146: syntax error : missing ';' before identifier 'value_type'Is there an #include I need to add to make this work?
ASKER
ASKER
#pragma once
#include <string>
#include "Author.h"
#include <iterator>
class Book
{
struct AuthorListNode {
Author data;
AuthorListNode* next;
};
public:
Book (std::string theTitle,
Author theAuthor,
std::string theIdentifier);
Book (std::string theTitle, int numberOfAuthors,
Author* theAuthors, std::string theIdentifier);
Book (const Book& b);
~Book();
Book& operator= (const Book&);
typedef AuthorIterator iterator;
typedef ConstAuthorIterator const_iterator;
std::string getTitle() const {return title;}
void putTitle(std::string theTitle) {title = theTitle;}
int getNumberOfAuthors() const {return numAuthors;}
void addAuthor (Author);
void removeAuthor (Author);
std::string getIdentifier() const {return identifier;}
void putIdentifier(std::string id) {identifier = id;}
iterator begin();
const_iterator begin() const;
iterator end();
const_iterator end() const;
iterator findAuthor (Name n);
const_iterator findAuthor (Name n) const;
private:
std::string title;
int numAuthors;
AuthorListNode* authors; // linked list of pointers to authors
std::string identifier;
friend class AuthorIterator;
friend class ConstAuthorIterator;
};
It now complains about line 27:
Book.h(27): error C2146: syntax error : missing ';' before identifier 'iterator'Also complains about lines 28, 42, 43, 45, 46, 48, 49.
using namespace std;
ASKER
typedef AuthorIterator std::iterator;
and it complains:
error C2955: 'std::iterator' : use of class template requires template argument list
ASKER
typedef std::iterator AuthorIterator;
and now it complains
error C2955: 'std::iterator' : use of class template requires template argument list
ASKER
C++ is an intermediate-level general-purpose programming language, not to be confused with C or C#. It was developed as a set of extensions to the C programming language to improve type-safety and add support for automatic resource management, object-orientation, generic programming, and exception handling, among other features.
TRUSTED BY
Yes, you are most likely to need to add
Open in new window
You could as well try to only use 'xutility' (which introduces it), but that way it's IMHO safer.