So, I'm having problems with my code. I'm simply trying to run an example code to see how it works (I'm a newbie at C++) and this error is appearing everytime I call the List class.
Here's the code:
//main.cpp
#include <iostream>
#include "List.h"
using namespace std;
int main() {
List<char> list;
// 5 types created using a 'for' loop
// and calling the ‘add’ function
for (int i = 101; i <= 105; i++)
{
list.add(char(i));
}
list.display();
// should output a, b, c, d, e
// in this example.
cout << endl;
return 0;
}
And here's the List class
//List.h
#pragma once
#include "Link.h"
template <class F> class List
{
private:
Link<F>* head;
public:
List();
int add(F theData);
void display();
};
and I'll also put List.cpp to help:
//List.cpp
#include "List.h"
template<typename F> List<F>::List()
{
// 'head' points to 0 initially and when the list is empty.
// Otherwise 'head' points to most recently
// added object head
head = 0;
}
template<typename F> void List<F>::display()
{
Link<F>* temp;// 'temp' used to iterate through the list
// 'head' points to last object added
// Iterate back through list until last pointer (which is 0)
for (temp = head; temp != 0; temp = temp->Next)
{
cout << "Value of type is " << temp->X << endl;
}
}
template<typename F> int List<F>::add(F theData)
{
// pointer 'temp' used to instantiate objects to add to list
Link<F>* temp;
// memory allocated and the object is given a value
temp = new Link<F>(theData);
if (temp == 0) // check new succeeded
{
return 0; // shows error in memory allocation
}
// the pointer in the object is set to whatever 'head' is pointing to
temp->Next = head;
// 'head' is re-directed to point to the last created object
head = temp;
return 1;
}
When I run, It gives me these errors:
PS. I'm using VS2017 btw.
Thank you