I have been receiving this error and it appears to be too vague for a Google search so I am handing it over to you! I am trying to create a linked list object that holds Account objects.
#include "Customer.h"
#include "LinkedList.h"
#include "Account.h"
#include "Mortgage.h"
#include "CurrentAcc.h"
#include "JuniorAcc.h"
#include "transaction.h"
#include <iostream>
#include <string>
using namespace std;
string name;
string address;
string telNo;
char gender;
string dateOfBirth;
list<Account> accList; // Error
list<Mortgage> mortList; //Error
I feel that I am not properly declaring my Linked Lists but cannot think of how else to do it.
The next piece of code I feel is as a result of my bad declaration.
void Customer::openCurrentAccount(int numb, double bal, int cl, string type, double Interest){
Current acc(numb,bal,cl,type,Interest); //Error - Expression must have class type.
accList.add(acc);
}
And here is the creation of my Linked List class .h file.
#pragma once
#include <iostream>
using namespace std;
template <class T>
class node;
template <class T>
class list
{
public:
list() { head = tail = NULL; }
~list();
void add(T &obj);
T remove(int ID);
void print(ostream &out);
T search(int ID);
private:
node<T> *head, *tail;
};
template <class T>
class node
{
public:
node() {next = NULL;}
//private:
T data;
node *next;
};
template <class T>
list<T>::~list()
{
}
You’re defining your own class called
listin the global namespace, and also puttingusing namespace std;in its header to dump the entire standard library into the global namespace. This means that you have two templates calledlistavailable in the global namespace, which will cause ambiguities and hence compile errors.You should:
using namespace std;in source files