I have searched many different questions and could not find a solution that matched my specific problem. I have this header file for a queue:
#ifndef HEADERFILE
#define HEADERFILE
#include <iostream>
#include <vector>
using namespace std;
template<class myType>
class Queue{
private:
int size;
vector<myType> list;
public:
Queue(int);
void Enqueue(myType);
myType Dequeue();
myType PeekFront();
int length();
void empty();
myType Index(int);
friend void printArray();
};
#endif
The issue in question is for friend void printArray
. Here is the implementation file:
#include "queueTask1.h"
#include <vector>
#include <iostream>
using namespace std;
(Other function implementations)
void printArray(){
for (int i = 0; i < list.size(); i++){
cout << list.at(i) << ", ";
}
cout << endl;
}
The error when attempting to run this states that
'list' is not declared in this scope
however it is declared in the header file and all other member functions work fine. For some reason printArray
cannot find the private data member list
, even though it should be a friend function.