VC++2005 error C2248 cannot access private member declared in class >>>>在线等
code:
--------------------------------list.h----------------------------------------
#ifndef LIST_H
#define LIST_H
#include "list_item.h"
template< class elemtype >
class list
{
list():_front(0), _end(0), _current(0), _size(0){}
...
~list() { remove_all() };
...
void insert_front( elemtype value );
...
private:
...
list_item< elemtype > *_front;
list_item< elemtype > *_end;
list_item< elemtype > *_current;
int _size;
};
#endif
-----------------------------------list.cpp---------------------------
#include "list.h"
#include <iostream>
template< typename elemtype >
void list< elemtype >::insert_front( elemtype value )
{
list_item *pflist = _front;
if( plist )
{
pflist->value( value );
pflist->next(_front);
_front = pflist;
}
}
-------------------------list_item.h---------------------------
#ifndef LIST_ITEM_H
#define LIST_ITEM_H
template< class elemtype >
class list_item
{
public:
list_item( elemtype value, list_item *item = 0 )
:_value( value )
{
if ( ! item )
_next = 0;
else
{
_next = item->_next;
item->_next = this;
}
}
elemtype value() { return _value; }
list_item* next() { return _next; }
void next( list_item *link ) { _next = link; }
void value ( elemtype value ) { _value = value; }
private:
elemtype _value;
list_item *_next;
};
#endif
------------------------------main.cpp---------------------------
#include "list.h"
#include <iostream>
int main()
{
list<int> mylist;
mylist.insert_front( 9 );
return 0;
}
---------------------------compile information----------------------
1>------ Build started: Project: list, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\main.cpp(6) : error C2248: 'list<elemtype>::list' : cannot access private member declared in class 'list<elemtype>'
1> with
1> [
1> elemtype=int
1> ]
1> c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\list.h(9) : see declaration of 'list<elemtype>::list'
1> with
1> [
1> elemtype=int
1> ]
1>c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\main.cpp(6) : error C2248: 'list<elemtype>::~list' : cannot access private member declared in class 'list<elemtype>'
1> with
1> [
1> elemtype=int
1> ]
1> c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\list.h(13) : see declaration of 'list<elemtype>::~list'
1> with
1> [
1> elemtype=int
1> ]
1>c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\main.cpp(8) : error C2248: 'list<elemtype>::insert_front' : cannot access private member declared in class 'list<elemtype>'
1> with
1> [
1> elemtype=int
1> ]
1> c:\documents and settings\leo\my documents\visual studio 2005\projects\list\list\list.h(17) : see declaration of 'list<elemtype>::insert_front'
1> with
1> [
1> elemtype=int
1> ]
1>Build log was saved at "file://c:\Documents and Settings\Leo\My Documents\Visual Studio 2005\Projects\list\list\Debug\BuildLog.htm"
1>list - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
请问为什么会有这个错误???