This question already has an answer here:
I typed up this class in my VectorBag.h file and realized that I needed to separate the implementation into another file. I received no compilation errors before separation, but now the compiler does not seem to recognize that the functions in my implementation file are templated. I get these types of errors for every function in the implementation file.
error: ‘ItemType’ was not declared in this scope
int VectorBag<ItemType>::getCurrentSize() const
^
error: template argument 1 is invalid
int VectorBag<ItemType>::getCurrentSize() const
How do I make the program recognize these functions when they are in VectorBag.cpp instead of VectorBag.h? I have included all of the interface file and the first part of the implementation file. Thanks.
/* VectorBag.h */
#ifndef _VECTOR_BAG
#define _VECTOR_BAG
#include<vector>
#include"BagInterface.h"
using namespace std;
template<class ItemType>
class VectorBag : public BagInterface<ItemType>
{
public:
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType& newEntry);
bool remove(const ItemType& anEntry);
void clear();
int getFrequencyOf(const ItemType& anEntry) const;
bool contains(const ItemType& anEntry) const;
vector<ItemType> toVector() const;
// New Bag Operations
//vector<ItemType> operator+(vector<ItemType> right);
private:
vector<ItemType> v;
};
#endif
/* VectorBag.cpp (partial) */
#include"VectorBag.h"
int VectorBag<ItemType>::getCurrentSize() const
{
return v.size();
}
Aucun commentaire:
Enregistrer un commentaire