编译问题

lianghongqing111 2002-10-16 06:13:03
编译下面第三个文件时总是出现以下错误,也许是很简单的问题,好象是头文件条件编译有问题,请高手指正。
c:\c++ files\stshtst3.cpp(10) : error C2065: 'stash' : undeclared identifier
c:\c++ files\stshtst3.cpp(10) : error C2146: syntax error : missing ';' before identifier 'intStash'
c:\c++ files\stshtst3.cpp(10) : error C2065: 'intStash' : undeclared identifier
c:\c++ files\stshtst3.cpp(12) : error C2228: left of '.add' must have class/struct/union type
c:\c++ files\stshtst3.cpp(15) : error C2146: syntax error : missing ';' before identifier 'stringStash'
c:\c++ files\stshtst3.cpp(15) : error C2065: 'stringStash' : undeclared identifier
c:\c++ files\stshtst3.cpp(18) : error C2228: left of '.add' must have class/struct/union type
c:\c++ files\stshtst3.cpp(20) : error C2228: left of '.count' must have class/struct/union type
c:\c++ files\stshtst3.cpp(21) : error C2228: left of '.fetch' must have class/struct/union type
c:\c++ files\stshtst3.cpp(22) : error C2228: left of '.count' must have class/struct/union type
c:\c++ files\stshtst3.cpp(23) : error C2228: left of '.fetch' must have class/struct/union type

文件:stash3.h

#ifdef STASH3_H_
#define STASH3_H_

class stash
{
int size;
int quantity;
int next;
unsigned char* storage;
void inflate(int increase);
public:
stash(int Size);
~stash();
int add(void* element);
void* fetch(int index);
int count();
};
#endif
-----------------------------------------------------------------------
文件:stash3.cpp

#include "stash3.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

stash::stash(int Size)
{
size=Size;
quantity=0;
storage=0;
next=0;
}

stash::~stash()
{
if(storage)
{
puts("freeing storage");
free(storage);
}
}

int stash::add(void* element)
{
if(next>=quantity)
inflate(100);
memcpy(&(storage[next *size]),element,size);
next++;
return(next-1);
}

void* stash::fetch(int index)
{
if(index>=next || index<0)
return 0;
return &(storage[index * size]);
}

int stash::count()
{
return next;
}

int stash::inflate(int increase)
{
void* v=realloc(storage,(quantity+increase)*size);
assert(v);
storage=(unsigned char*)v;
quantity+=increase;
}
-----------------------------------------------------------------------
文件:stshtst3.cpp

#include "stash3.h"
#include <stdio.h>
#include <assert.h>
#define BUFSIZE 80


void main()
{

stash intStash(sizeof(int));
for(int j=0;j<100;j++)
intStash.add(&j);
FILE* file=fopen("STASHTST.CPP","r");
assert(file);
stash stringStash(sizeof(char) * BUFSIZE);
char buf[BUFSIZE];
while(fgets(buf,BUFSIZE,file))
stringStash.add(buf);
fclose(file);
for(int k=0;k<intStash.count();k++)
printf("intStash.fetch(%d)=%d\n",k,*(int*)intStash.fetch(k));
for(int i=0;i<stringStash.count();i++)
printf("stringStash.fetch(%d)=%s",i,(char*)stringStash.fetch(i++));
putchar('\n');
}
...全文
80 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lianghongqing111 2002-10-18
  • 打赏
  • 举报
回复
楼上说的没错,是预处理出了问题(字母大小写问题)。
qrlvls 2002-10-16
  • 打赏
  • 举报
回复
实际上只有一个错误,能不能吧stash3的相关内容贴出来?

stash类型定义没有生效(可能是因为预处理)或者根本没有定义

16,548

社区成员

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

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

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