Hi I was working on a project that required a linked list for a class. I thought that adding another variable to the node class would be helpful during the project to keep track of something but the way I have implemented it seems to not be working. I was under the impression that friend classes can see the private data of the class it is friends with. My linked list class even displays this working with the data variable (shown below). As soon as I implemented the "marker" variable I get an undeclared identifier. If anyone can help me clear up the issue as to why this is happening because it makes no sense to me. Thanks!
btw heres my header file
template <class T>
class linkedListClass;
template <class T>
class nodeClass
{
public:
nodeClass(){next=NULL;};
friend linkedListClass<T>;
private:
int marker;
T data;
nodeClass *next;
};
template <class T>
class linkedListClass
{
public:
linkedListClass(){head=tail=NULL;};
~linkedListClass();
bool isEmpty()const{return head==NULL;};
bool isFull()const{return false;};
int isMarked();
void markBeenThere(int newMark);
void addItemToHead(T newItem);
void addItemToTail(T newItem);
void free();
void addItemInOrder(T newItem);
T removeFirst();
T removeLast();
private:
nodeClass<T> *head, *tail;
};

friend class question
tushar.k
I wasn't able to reproduce the error. Could you post the sample leading to the error
As you said friend classes should be able to access private members.
I just tried the following small sample (derived from yours) using VC2005 and all behaved as expected.
//g.h
#include <stdio.h>
template <class T>
class linkedListClass;
template <class T>
class nodeClass
{
public:
nodeClass(){next=0;};
friend linkedListClass<T>;
private:
int marker;
T data;
nodeClass *next;
};
template <class T>
class linkedListClass
{
public:
linkedListClass(){head.marker=tail.marker=5; printf ("marker=%d\n",tail.marker);}
private:
nodeClass<T> head, tail;
};
//g.cpp
#include <iostream>
#include <stdio.h>
#include "g.h"
void main(){
linkedListClass<int> *mylist = new linkedListClass<int>;
}
I then compiled the g.cpp (compilation command: cl /EHsc g.cpp). No errors were generated by the compiler. I then ran g.exe and it printed out: marker=5
Hope this helps!
Thanks,
Ayman Shoukry
VC++ Team