VC++里面,Stack怎么写?我写了个,好多错! 帮忙看看!
//tristStack.h
#ifndef _TRISTSTACK_H_INCLUDE
#define _TRISTSTACK_H_INCLUDE
#include "Trist.h"
class tristStack {
public:
tristStack();
~tristStack();
void pushTrist (Trist t);
Trist popTrist ();
bool isEmpty();
int getSize();
Trist head;
tristStack next;
int size;
};
#endif
//tristStack.cpp
#include "tristStack.h"
tristStack::tristStack() {
head = null;
next = null;
size=0;
}
tristStack::~tristStack() {
}
bool tristStack::isEmpty () {
if (size == 0)
return true;
return false;
}
int tristStack::getSize() {
return size;
}
void tristStack::pushTrist(Trist t){
next = this;
head = t;
size++;
}
Trist tristStack::popTrist() {
Trist temp = head;
head = next.head;
next = next.next;
size--;
return temp;
}
//error message when built
--------------------Configuration: Delaunay2D - Win32 Debug--------------------
Compiling...
computeDT.cpp
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(19) : error C24 (more...)
C++ 中...
1. null 必须大写,也就是 NULL;
2. 类tristStack还没定义,所以不能用;可用指针.
下面是改过的程序:
//tristStack.h
#ifndef _TRISTSTACK_H_INCLUDE
#define _TRISTSTACK_H_INCLUDE
#include "Trist.h"
class tristStack {
public:
tristStack();
~tristStack();
void pushTrist (Trist t);
Trist popTrist ();
bool isEmpty();
int getSize();
Trist head;
void * next;
int size;
};
#endif
//tristStack.cpp
#include "tristStack.h"
tristStack::tristStack() {
head = Trist();
next = NULL;
size=0;
}
tristStack::~tristStack() {
}
bool tristStack::isEmpty () {
if (size == 0)
return true;
return false;
}
int tristStack::getSize() {
return size;
}
void tristStack::pushTrist(Trist t){
next = this;
head = t;
size++;
}
Trist tristStack::popTrist() {
Trist temp = head;
head = ((tristStack *)next)->head;
next = ((tristStack *)next)->next;
size--;
return temp;
}
2. 类tristStack还没定义,所以不能用;可用指针.
下面是改过的程序:
//tristStack.h
#ifndef _TRISTSTACK_H_INCLUDE
#define _TRISTSTACK_H_INCLUDE
#include "Trist.h"
class tristStack {
public:
tristStack();
~tristStack();
void pushTrist (Trist t);
Trist popTrist ();
bool isEmpty();
int getSize();
Trist head;
void * next;
int size;
};
#endif
//tristStack.cpp
#include "tristStack.h"
tristStack::tristStack() {
head = Trist();
next = NULL;
size=0;
}
tristStack::~tristStack() {
}
bool tristStack::isEmpty () {
if (size == 0)
return true;
return false;
}
int tristStack::getSize() {
return size;
}
void tristStack::pushTrist(Trist t){
next = this;
head = t;
size++;
}
Trist tristStack::popTrist() {
Trist temp = head;
head = ((tristStack *)next)->head;
next = ((tristStack *)next)->next;
size--;
return temp;
}