I have a header file named ArrayBag.h
/** Header file for an array-based implementation of the ADT bag.
@file ArrayBag.h */
#ifndef _ARRAY_BAG
#define _ARRAY_BAG
#include "BagInterface.h"
template<class ItemType>
class ArrayBag : public BagInterface<ItemType>
{
.
.
.
.
.
}; // end ArrayBag
#include "ArrayBag.cpp"
#endif
Then I have the i have the implementation file ArrayBag.cpp which implements some of the methods.
/* Implementation file for the class ArrayBag.
@file ArrayBag.cpp */
#include "ArrayBag.h"
template<class ItemType>
ArrayBag<ItemType>::ArrayBag(): itemCount(0), maxItems(DEFAULT_CAPACITY) {
}// end default constructor
.
.
.
.
.
.
basically implement more methods
The BagInterface class just contains virtual methods so that is not the problem but the problem seems to be an infinite recursion of the header and the code file.
for example in a test file main.cpp
#include <iostream>
#include <string>
#include "ArrayBag.h"
using namespace std;
int main(){
/// some code to test it
}
But when i run to build it I keep getting method_name function template has already been defined. I have tried removing
#include "ArrayBag.h"
but then it wont build so i just dont know I for the love of god cannot figure it out please help me I am going insane.