VC为什么不能自动找到我的类成员函数定义?(20)

oneonone 2003-07-11 08:36:36
我先自己写好了Stack.cpp和Stack.h两个文件,在头文件中定义了类,并声明了成员函数,然后建立了一个WIN32 APP 将我自己的两个文件加入到这个工程中,在Class View中出现了我所定义的类,以及相应的成员函数,但是就是不能通过双击Class View中的函数名称来到达函数定义处,总是弹出一个对话框"Can not find the defination"implementation"of this function"请问这是为什么?
...全文
154 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
oneonone 2003-07-11
  • 打赏
  • 举报
回复
哪位帮我调一下,我已经仔细查过了,函数的声明和具体的实现都是没有问题的.
oneonone 2003-07-11
  • 打赏
  • 举报
回复
//Stack.h
//类的声明在这里

#define STACK_INIT_SIZE 100 //堆栈空间分配的初始大小
#define STACKINCREMENT 50 //堆栈的空间分配增量

#define STACK_OVERFLOW 0x03 //溢出错
#define STACK_EMPYT 0x04 //栈空错
#define NOT_ENOUGH_MEMORY 0x05 //可供分配的内存不足
#define STACK_EMPTY 0x06 //栈为空
#define STACK_NOT_EMPTY 0x07 //栈不为空

template <class type>class CSqStack
{
private:
type *base,*top; //栈顶和栈底指针
int stacksize; //栈的当前总容量

public:
CSqStack(); //初始化一个空栈
~CSqStack(); //销毁一个栈
int ClearStack(); //将栈清空
int StackEmpty(); //判断栈是否为空
int StackLength(); //返回栈当前拥有元素的个数
type GetTop(); //获得栈顶元素
int Push(type elem); //压栈
int Pop(type &elem); //出栈
int StackTraverse(int *(visit)(type elem)); //用VISIT方法对所有元素进行访问
};



oneonone 2003-07-11
  • 打赏
  • 举报
回复
//函数的声明在这里
//Stack.cpp

#include "CSqstack.h"
//CSqStack(); //初始化一个空栈 构造函数
template <class type>CSqStack<type>::CSqStack()
{
base = (type *)malloc( SATCK_INIT_SIZE * sizeof( type ) );
if(base == NULL) //内存分配失败
exit(NOT_ENOUGH_MEMORY); //这里在WIN底下不能运行
top = base;
stacksize = SATCK_INIT_SIZE;
}
// ~CSqStack(); //销毁一个栈 析构函数
template <class type> CSqStack<type>::~CSqStack()
{
free( base );
}
// int ClearStack(); //将栈清空 成功后返回OK 失败后ERROR
template <class type> int CSqStack<type>::ClearStack()
{
top = base;
return OK;
}

// int StackEmpty(); //判断栈是否为空
template <class type> int CSqStack<type>::StackEmpty()
{
if( top == base) //栈空
return( STACK_EMPTY);
else //栈不空
return( STACK_NOT_EMPTY);
}

// int StackLength(); //返回栈当前拥有元素的个数
template <class type> int CSqStack<type>::StackLength()
{
int count = 0;
type current;
current = top;
while( current != base )
{
count++;
current--; //指向下一个元素
}
return(count);
}
// type GetTop(); //获得栈顶元素 此处有一个问题,如果type为类变量,则此type必须重载=运算符
template <class type> type CSqStack<type>::GetTop()
{
type current;
current = top;
current--;
return(*current);
}
// int Push(); //压栈 有可能返回OK,或者内存分配失败,程序直接退出
template <class type> int CSqStack<type>::Push(type elem) //参数:elem 需要压入的量
{
if((top - base) >= stacksize) //栈满,追加空间
{
base = (type *)realloc(base , (stacksize + STACKINCREMENT) * sizeof(type));
if(!base) //存储分配失败
exit(NOT_ENOUGH_MEMORY);
top = base + stacksize;
stacksize += STACKINCREMENT;
}
*(top++) = e;
return OK;
}
// int Pop(type &elem); //出栈 参数为传指针调用,用于返回弹出的值
template <class type> int CSqStack<type>::Pop(type &elem) //成功后返回OK,失败后返回STACK_EMPTY
{
if(top = base) //栈为空,无法出栈
return(STACK_EMPTY);
elem = *(--top);
return OK;
}

// int StackTraverse(int *(visit)(type elem)); //用VISIT方法对所有元素进行访问
template <class type> int CSqStack<type>::StackTraverse(int *(visit)(type elem)) //成功访问所有元素后返回OK
{
type *current;
current = top;
while(current != base)
{
visit(*current);
current--;
}
return OK;
}



slyfox 2003-07-11
  • 打赏
  • 举报
回复
肯定是你的代码的错误

函数定义要一致, 不是编译通过了,就行
zhouyong0371 2003-07-11
  • 打赏
  • 举报
回复
有时候是会这样

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧