C++ list链表问题 这些错误是为什么啊
#include "stdafx.h"#include<iostream>
using namespace std;
//---------------------
class TNode
{
friend class TList;
friend ostream& operator<<(ostream& os,TNode& node);
public:
TNode(int data=0);
private:
int m_data;
TNode* next;
};
ostream& operator<<(ostream& os,TNode& node)
{
os<<node.m_data;
return os;
}
TNode::TNode(int data)
{
m_data = data;
next = NULL;
}
//----------------------
class TList
{
public:
void InsertFirst(int data);
void InsertLast(int data);
public:
void Show();
private:
TNode* Tail();
private:
TNode head;
};
void TList::Show()
{
TNode* p = this->head.next;
while(p != NULL)
{
cout<<(*p)<<" ";
//
p = p->next;
}
cout<<endl;
}
TNode* TList::Tail()
{
//节点的next==NULL
TNode* p = &head;
while(p->next != NULL)
p = p->next;
return p;
}
void TList::InsertLast(int data)
{
//找到最后一个节点
TNode* last = Tail();
//创建一个新节点:构造函数中赋值
TNode* pNode = new TNode(data);
//插入链表:位置
last->next = pNode;
}
void TList::InsertFirst(int data)
{
//创建一个新节点:构造函数中赋值
TNode* pNode = new TNode(data);
//插入链表:位置
pNode->next = this->head.next;
this->head.next = pNode;
}
//=========================================
//
template<class T>
T Add(T x,T y)
{
return x+y;
}
//----------------------------------------
int main(int argc, char* argv[])
{
TList lst;
lst.InsertFirst(1);
lst.InsertFirst(10);
lst.InsertFirst(19);
lst.InsertLast(29);
lst.InsertLast(129);
lst.Show();
int n = Add(1,10);
double fn = Add<double>(1.0,2.3);
//------------------------
return 0;
}
error C2248: 'm_data' : cannot access private member declared in class 'TNode'
list\list.cpp(16) : see declaration of 'm_data'
list\list.cpp(48) : error C2593: 'operator <<' is ambiguous