我想在MFC对话框中建立一个堆栈,代码如下:
typedef struct {
double *elem;
int top;
}Stack;
然后就是初始化程序:
int InitStack(Stack *S)
{
S->elem = (double *) new (256*sizeof(double));
S->top =0;
}
但是始终不能通过编译,出现错误是:
error C2061: syntax error : identifier 'Stack'
error C2511: 'InitStack' : overloaded member function 'int (CStackDlg::Stack *)' not found in 'CStackDlg'
请各位大虾指教一下这是什么原因?
谢谢谢谢!
typedef struct {
double *elem;
int top;
}Stack;
然后就是初始化程序:
int InitStack(Stack *S)
{
S->elem = (double *) new (256*sizeof(double));
S->top =0;
}
但是始终不能通过编译,出现错误是:
error C2061: syntax error : identifier 'Stack'
error C2511: 'InitStack' : overloaded member function 'int (CStackDlg::Stack *)' not found in 'CStackDlg'
请各位大虾指教一下这是什么原因?
谢谢谢谢!
double *elem;
int top;
}Stack;
{
double *elem;
int top;
}Stack;
你别把new当malloc用阿
double *elem;
int top;
}
Stack;int InitStack(Stack *S)
{
S->elem = (double *) new double[256];
S->top =0;
return 0;
}
可能头文件没有包含在StackDlg.h或StackDlg.cpp中
Stack只是作为一个结构在类中出现,并没有生成Stack类!
是不是应该要包含stack.h啊?
但是应该在哪里包含呢?
typedef struct tagStack{
double *elem;
int top;
}Stack;
以后,类变量栏中并没有Stack这个变量!