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 C2460: 'next' : uses 'tristStack', which is being defined
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(7) : see declaration of 'tristStack'
tristStack.cpp
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(19) : error C2460: 'next' : uses 'tristStack', which is being defined
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(7) : see declaration of 'tristStack'
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(5) : error C2065: 'null' : undeclared identifier
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(25) : error C2440: '=' : cannot convert from 'class tristStack *const ' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(32) : error C2228: left of '.head' must have class/struct/union type
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(33) : error C2228: left of '.next' must have class/struct/union type
Error executing cl.exe.
test2.exe - 6 error(s), 0 warning(s)
难道VC++里面,null也不能用么?
//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 C2460: 'next' : uses 'tristStack', which is being defined
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(7) : see declaration of 'tristStack'
tristStack.cpp
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(19) : error C2460: 'next' : uses 'tristStack', which is being defined
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.h(7) : see declaration of 'tristStack'
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(5) : error C2065: 'null' : undeclared identifier
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(25) : error C2440: '=' : cannot convert from 'class tristStack *const ' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(32) : error C2228: left of '.head' must have class/struct/union type
d:\urop\myproj\delaunayvisualiser\delaunay2d\triststack.cpp(33) : error C2228: left of '.next' must have class/struct/union type
Error executing cl.exe.
test2.exe - 6 error(s), 0 warning(s)
难道VC++里面,null也不能用么?