登录 | 首页 -> 华新鲜事 -> 社会百科 | 切换到:传统版 / sForum | 树形列表
VC++里面,Stack怎么写?
<<始页  [1]  末页>> 

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也不能用么?
[maserati (6-29 14:54, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

c++和java不一样的。。[hula (6-29 18:28, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

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;
}
[风中的树叶 (6-29 21:36, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

(引用 风中的树叶:C++ 中...1. null 必须大写,也就是 NULL; 2. 类tristStack还没定义,所以不能用;可用指针. 下面是改过的程序: //tristStack.h #ifndef _...)谢谢[maserati (6-29 22:35, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 社会百科 | [刷新本页] | 切换到:传统版 / sForum