我在vc6新建空win32应用程序,新建类,然后编译的时候vc说不认是NULL空指针
解决方案 »
- LIST iterator类型的pit,后移问题 >_< 在线等,谢谢各位,嘻嘻
- 请问VC++ 6.0、VC++ 2008、VC++.NET 是什么关系?
- 选取位图资源文件的一个矩形区,生成一个位图对象?
- [VC/MFC]为什么在基于对话框的程序中无法在线程中生成类似msn的消息框
- 如何注册自己创建的COM
- 端控制多台客户端,实现其间通信的程序?急!100分感谢!
- 在那里有关于DLL开发的好书请推荐,在用向导生成DLL工程时,那三个选项是什么意思,注释中AFX_MANAGE_STATE宏又是什么意思,请高手指教!
- 我想自己建一个类,哪位高手能帮我选一个合适的基类?
- 关于一个C的数学程序的简单问题,可是就是找不到出错的地方...
- 读写文件冲突。
- 救命!!!MS Remote Data Control的属性配置~``````
- 最快捷的得到如“2003-12-24 12:36:00”格式时间办法是什么?
#include "stdafx.h"
int *p=0;
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
enum Boolean {False,True};
class List;
class ListIterator;class ListNode
{
friend class List;
friend class ListIterator;
public:
ListNode();
virtual ~ListNode();
ListNode(const char value):data(value),link(NULL){};
ListNode(const char& item);
ListNode * NextNode(){return link;}
void InsertAfter(ListNode *p);
ListNode * GetNode(const char & item,ListNode * next);
ListNode * RemoveAfter();
private:
char data;
ListNode * link;};class List{
public:
List(const char & value) {last=first=new ListNode(value);};//构造函数
~List();
void MakeEmpty();
int Length() const;
ListNode *Find(char value);
ListNode * Find(int i);
int Insert(char value,int i); //将新元素插入到i位置
char * Remove(int i);
char * Get(int i);
private:
ListNode * first,last;
};
class ListIterator{
public:
ListIterator(const List & l):list(l),current(l.first){};
Boolean NotNull();
Boolean NextNotNull();
char * First();
char * Next();
private:
const List & list;
ListNode * current;
}ListNode::ListNode():link(NULL){}ListNode::~ListNode()
{}ListNode::ListNode(const char & item):data(item),link(NULL){
}void ListNode::InsertAfter(ListNode *p){
//将p所指的节点链接成当前节点的后继节点
p->link=link;
link=p;
}ListNode * ListNode::GetNode(const char & item,ListNode * next=NULL){
//以item和next建立一个新节点,并返回其地址
ListNode *newnode=new ListNode(item);
newnode->link=next;
newnode->link=next;
return newnode;
}ListNode * ListNode::RemoveAfter(){
//从链中摘下当前的下一个节点,返回其地址
ListNode * temp=link;
if (link==NULL) return NULL;
link=temp->link;
return temp;
}
//下面是List类List::~List(){
MakeEmpty();
delete first;
}
void List::MakeEmpty(){
//将链表置为空表
ListNode *q;
while (first->link!=NULL){
q=first->link;
first->link=q->link;
delete q;
}
last=first;
}int List::Length() const {
ListNode * p=first->link;
int count=0;
while (p!=NULL){
p=p->link;
count++;
}
return count;}ListNode * List::Find(char value){
//
ListNode *p=first->link;
while(p!=NULL && p->data!=value)
p=p->link;
return p;}
ListNode * List::Find(int i){
if (i<-1) return NULL:
if (i==-1) return first;
ListNode * p=first->link;
int j=0;
while (p!=NULL && j<i){
p=p->link;
j++;
}
return p;
}int List::Insert(char value,int i){
//将新元素value插入到i,成功则返回1,否返回0
ListNode *p=Find(i-1);
if (p==NULL) return 0;
ListNode * newnode=GetNode(value,p->link);
if (p->link==NULL) last=newnode;
p->link=newnode;
return 1;
}
char * List::Remove(int i)
{
ListNode *p=Find(i-1),*q;
if (p==NULL||p->link==NULL) return NULL:
q=p->link;
p->link=q->link;
char value=q->data;
if (q==last) last=p;
delete q;
return & value;
}char * List::Get(int i)
{
ListNode *p=Find(i);
if (p==NULL||p==first) return NULL;
else return &p->data;
}Boolean ListIterator::NotNull()
{
if (current!=NULL) return True;
else return False;
}
Boolean ListIterator::NextNotNull()
{
if (current!=NULL&& current->link!=NULL) return True;
else return False;
}
char * ListIterator::First()
{
if (list.first->link!=NULL)
{
current=list.first;
return & current->data; }
else
{
current=NULL;
return NULL;
}
}char * ListIterator::Next()
{
if (current!=NULL && current->link!=NULL){
current=current->link;
return & current->data; }
else
{
current=NULL;
return NULL;
}
}int main()
{
/* */
return 1;
}
class Stack;
class Node
{
friend class Stack;
public:
Node(char d=0,Node * l=NULL):data(d),link(l){}
private:
char data; //节点数据域
Node * link; //指针域
};class Stack
{
public:
Stack():top(NULL){};
~Stack();
void Push(const char & item);
char Pop();
char GetTop();
void MakeEmpty();
int IsEmpty() const {return top==NULL;}
private:
Node * top;
};Stack::~Stack()
{
if (!IsEmpty()) MakeEmpty();
}void Stack::MakeEmpty()
{
Node *p;
while(top!=NULL){
p=top;
top=top->link;
delete p;
}
}void Stack::Push(const char &item){
top=new Node(item,top);
}char Stack::Pop()
{
//删除栈顶元素,并返回她的值
if (IsEmpty() ) return 0;
Node * p=top;
char retvalue=p->data;
top=top->link;
delete p;
return retvalue;
}char Stack::GetTop()
{
if (IsEmpty()) return 0;
return top->data;
}int main()
{
return 1;
}
出错
ompiling...
Expr.cpp
E:\MyDoc\c++\Expr\Expr.cpp(9) : error C2065: 'NULL' : undeclared identifier
E:\MyDoc\c++\Expr\Expr.cpp(9) : error C2440: 'default argument' : cannot convert from 'int' to 'class Node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\MyDoc\c++\Expr\Expr.cpp(37) : error C2446: '!=' : no conversion from 'int' to 'class Node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\MyDoc\c++\Expr\Expr.cpp(37) : error C2040: '!=' : 'class Node *' differs in levels of indirection from 'int'
Error executing cl.exe.Expr.exe - 4 error(s), 0 warning(s)
加如下的预编译语句#ifndef NULL
#define NULL 0
#endif
楼上方法可以解决!
#define NULL 0
#endif
NULL 就是0