K
Kain0o0
Hello , thanks for any help in advance.
Im writing some code for a c++ class and the proffessor wants us to
implement a list template using arrays.
I thought this would be an easy task but have been stuck with the same
error and i cant seem to fix it. I think its the constructor but i dont
know how to fix it .
My error is:
List error LNK2019: unresolved external symbol "public: __thiscall
List<double,80>::List<double,80>(void)" (??0?$List@N$0FA@@@QAE@XZ)
referenced in function _main
My Code:
********
list.h
********
template <class DATA, int MAX_LIST_SIZE>
class List
// Stores a list of DATA with the member functions shown below.
// Positions in the list are numbered starting with 1 (not 0).
{
public:
// constuctors -- no destructor needed
List();
List(const List<DATA,MAX_LIST_SIZE>& original);
// accessors
bool isEmpty() const;
bool isFull() const;
int getLength() const { return _firstOpen; }
DATA retrieve (int position, bool& success) const;
// mutators
void insert (int position, DATA newItem, bool& success);
// inserts newItem into specifice position
// --- except that, if position is past the end of the list,
// inserts at the end of the list
void remove(int position, bool& success);
private:
DATA _element[MAX_LIST_SIZE];
// For space efficiency, I'll store the 1st element
// in position 0; the second, in position 1, etc.
int _firstOpen;
};
*********
list.h
*********
#include "list.h"
template <class DATA, int MAX_LIST_SIZE>
List<DATA,MAX_LIST_SIZE>::List()
{
_firstOpen=0;
DATA _element[MAX_LIST_SIZE];
}
/*template <class DATA, int MAX_LIST_SIZE>
List<DATA,MAX_LIST_SIZE>::List(const List<DATA,MAX_LIST_SIZE>&
original)
{
DATA=original.DATA;
MAX_LIST_SIZE=original.MAX_LIST_SIZE;
//DATA _element[MAX_LIST_SIZE];
}
*/
template <class DATA, int MAX_LIST_SIZE>
bool List<DATA,MAX_LIST_SIZE>::isEmpty() const
{
return _firstOpen==0;
}
template <class DATA, int MAX_LIST_SIZE>
bool List<DATA,MAX_LIST_SIZE>::isFull() const
{
return _firstOpen==MAX_LIST_SIZE;
}
template <class DATA, int MAX_LIST_SIZE>
void List<DATA,MAX_LIST_SIZE>::insert(int position, DATA newItem, bool&
success)
{
if(position > MAX_LIST_SIZE)
{
DATA _element[MAX_LIST_SIZE]=newItem;
}
else
{
DATA _element[position]=newItem;
}
}
template <class DATA, int MAX_LIST_SIZE>
void List<DATA,MAX_LIST_SIZE>::remove(int position, bool& success)
{
DATA _element[position]="deleted";
}
template <class DATA, int MAX_LIST_SIZE>
DATA List<DATA,MAX_LIST_SIZE>::retrieve (int position, bool& success)
const
{
return DATA _element[position];
}
********
listTest
********
#include "list.h"
#include <iostream>
using namespace std;
int main()
{
List<double,80> test;
return 0;
};
Im writing some code for a c++ class and the proffessor wants us to
implement a list template using arrays.
I thought this would be an easy task but have been stuck with the same
error and i cant seem to fix it. I think its the constructor but i dont
know how to fix it .
My error is:
List error LNK2019: unresolved external symbol "public: __thiscall
List<double,80>::List<double,80>(void)" (??0?$List@N$0FA@@@QAE@XZ)
referenced in function _main
My Code:
********
list.h
********
template <class DATA, int MAX_LIST_SIZE>
class List
// Stores a list of DATA with the member functions shown below.
// Positions in the list are numbered starting with 1 (not 0).
{
public:
// constuctors -- no destructor needed
List();
List(const List<DATA,MAX_LIST_SIZE>& original);
// accessors
bool isEmpty() const;
bool isFull() const;
int getLength() const { return _firstOpen; }
DATA retrieve (int position, bool& success) const;
// mutators
void insert (int position, DATA newItem, bool& success);
// inserts newItem into specifice position
// --- except that, if position is past the end of the list,
// inserts at the end of the list
void remove(int position, bool& success);
private:
DATA _element[MAX_LIST_SIZE];
// For space efficiency, I'll store the 1st element
// in position 0; the second, in position 1, etc.
int _firstOpen;
};
*********
list.h
*********
#include "list.h"
template <class DATA, int MAX_LIST_SIZE>
List<DATA,MAX_LIST_SIZE>::List()
{
_firstOpen=0;
DATA _element[MAX_LIST_SIZE];
}
/*template <class DATA, int MAX_LIST_SIZE>
List<DATA,MAX_LIST_SIZE>::List(const List<DATA,MAX_LIST_SIZE>&
original)
{
DATA=original.DATA;
MAX_LIST_SIZE=original.MAX_LIST_SIZE;
//DATA _element[MAX_LIST_SIZE];
}
*/
template <class DATA, int MAX_LIST_SIZE>
bool List<DATA,MAX_LIST_SIZE>::isEmpty() const
{
return _firstOpen==0;
}
template <class DATA, int MAX_LIST_SIZE>
bool List<DATA,MAX_LIST_SIZE>::isFull() const
{
return _firstOpen==MAX_LIST_SIZE;
}
template <class DATA, int MAX_LIST_SIZE>
void List<DATA,MAX_LIST_SIZE>::insert(int position, DATA newItem, bool&
success)
{
if(position > MAX_LIST_SIZE)
{
DATA _element[MAX_LIST_SIZE]=newItem;
}
else
{
DATA _element[position]=newItem;
}
}
template <class DATA, int MAX_LIST_SIZE>
void List<DATA,MAX_LIST_SIZE>::remove(int position, bool& success)
{
DATA _element[position]="deleted";
}
template <class DATA, int MAX_LIST_SIZE>
DATA List<DATA,MAX_LIST_SIZE>::retrieve (int position, bool& success)
const
{
return DATA _element[position];
}
********
listTest
********
#include "list.h"
#include <iostream>
using namespace std;
int main()
{
List<double,80> test;
return 0;
};