error C2995: 'Iterator<ElemType>::Iterator(void)' : function template has already been defined
C2065 is not showing now
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef _iterator_h
#define _iterator_h
/*
* Class: Iterator
* ---------------
* This class is used to iterate over a collection of elements.
*/
template <typename ElemType>
class Iterator {
public:
/*
* Constructor: Iterator
* Usage: iter = new Iterator<double>();
* ------------------------------------
* The constructor allocates a new iterator with no entries.
*/
Iterator();
/*
* File: iterator.h
* CS106 Section Leader: Alan Viverette
* Last modified on Fri June 8 09:50:00 2012 by granite
*
* -----------------------------------------------------
* This file implements an iterator class template.
* You should not need to modify this file.
*/
#ifndef _iterator_h
#define _iterator_h
/*
* Class: Iterator
* ---------------
* This class is used to iterate over a collection of elements.
*/
template <typename ElemType>
class Iterator {
public:
/*
* Constructor: Iterator
* Usage: iter = new Iterator<double>();
* ------------------------------------
* The constructor allocates a new iterator with no entries.
*/
Iterator();
/*
* Destructor: ~Iterator
* Usage: delete iter;
* --------------------
* The destructor frees the storage associated with the
* iterator.
*/
~Iterator();
/*
* Member function: hasNext
* Usage: if (iter.hasNext())...
* ------------------------------
* This function returns true until all the values are
* exhausted, after which it returns false.
*/
bool hasNext();
/*
* Member function: next
* Usage: value = iter.next();
* ----------------------------
* This function advances the iterator and returns the
* the next value. An Error is raised if next is called
* when hasNext would return false.
*/
ElemType next();
/*
* Member function: add
* Usage: iter.add(elem);
* ------------------------------
* This function adds a new element to the iterator. It is
* intended to be called by the container when initializing
* the iterator to hold the collection values to be
* iterated over.
*/
void add(ElemType elem);
private:
struct cellT {
ElemType elem;
cellT *link;
};
cellT *start, *tail;
};
#include "iterator.cpp"
#endif
You shall all definition of your template class transfer to the header file. So you will have one header file in which there will be the class declaration and its definitions.
so... confusion follows and the compiler becomes confused, then I ma confused, but since the compiler was already confused then I simply was already confused?
As I said you should all definitions of your class to place into the same header file. So you will have one header file that will contain all definitions of your template class.