头文件里定义的结构体数组在源文件里出现错误

rach09 2011-05-09 07:05:42
vc6.0

头文件里定义
struct MFD{
char nam[20]; //user name
UDM* d_a; //user directory address
int count; //user have how many file
} mfd[N];
在cpp里这样使用
void iniMFD(){
mfd[0].nam="r1";
}

会提示:
C:\me\os\fileOperate\a.cpp(8) : error C2065: 'mfd' : undeclared identifier
C:\me\os\fileOperate\a.cpp(8) : error C2109: subscript requires array or pointer type
C:\me\os\fileOperate\a.cpp(8) : error C2228: left of '.nam' must have class/struct/union type
...全文
319 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
晨星 2011-05-13
  • 打赏
  • 举报
回复
把头文件里前面的#if(_VER_MSC > 1000)和最后的#endif都去掉吧。
你从哪里看来的代码啊?我用的的Visual C++ 2010里面好像都不支持“_VER_MSC”这么个宏。
rach09 2011-05-09
  • 打赏
  • 举报
回复
头文件:g.h

struct H{
int i;
}h[3];
.cpp:

#include <iostream>
#include "g.h"
using namespace std;
h[0].i=1;
void main(){
}
提示:
--------------------Configuration: returnTemp - Win32 Debug--------------------
Compiling...
returnTemp.cpp
C:\me\test\cpp\returnTemp.cpp(6) : error C2466: cannot allocate an array of constant size 0
C:\me\test\cpp\returnTemp.cpp(6) : error C2143: syntax error : missing ';' before '.'
C:\me\test\cpp\returnTemp.cpp(6) : error C2501: 'h' : missing storage-class or type specifiers
C:\me\test\cpp\returnTemp.cpp(6) : error C2371: 'h' : redefinition; different basic types
c:\me\test\cpp\g.h(4) : see declaration of 'h'
C:\me\test\cpp\returnTemp.cpp(6) : error C2143: syntax error : missing ';' before '.'
Error executing cl.exe.

returnTemp.obj - 5 error(s), 0 warning(s)
rach09 2011-05-09
  • 打赏
  • 举报
回复
头文件(a.h):
#if(_VER_MSC > 1000)
#pragma once
//#include <iostream>

#define N 10 //有N个用户
#define L 20 //每个用户可以有L个文件
#define S 10 //允许一个用户最多可以同时打开S个文件
#define recodeLen 50 //每个记录的长度

enum fileAttribute{r,rw}; //r is read ; two is rw and write
enum fileStatus{n_open,n_close}; //
struct MFD{
char nam[20]; //user name
UDM* d_a; //user directory address
int count; //user have how many file
} mfd[N];

struct UFD{
char nam[20]; //file name
enum att; //file attribute is read and readWrite
char len[recodeLen]; //recode length
int curLen; //current hold charaters numeric
FILE* add; //file address
}ufd[L];

struct UOF{
char nam[20]; //file name
enum att; //file attribute is read and readWrite
char len[recodeLen]; //recode length
fileStatus sta;
FILE* r_ptr;
FILE* w_ptr;
}uof[S];

#endif //pragma once


cpp文件:
#include <iostream>
#include "a.h"
using namespace std;

//mfd[0].nam="r1";

void iniMFD(){
mfd[0].nam="r1";
// mfd[0].d_a=0;
// mfd[0].count=0;

// add user
}
void iniUFD(){
}
bool matchUser(char name[]){
return true;
}

int main(){
system("pause");
return 0;
}
bargio_susie 2011-05-09
  • 打赏
  • 举报
回复
至于'mfd' : undeclared identifier这个错误就要看你有没包含那个定义那个结构的头文件了
bargio_susie 2011-05-09
  • 打赏
  • 举报
回复
strcpy(mfd[0].nam, "r1");
晨星 2011-05-09
  • 打赏
  • 举报
回复
这几行里似乎看不出毛病,需要更多上下文了。
头文件包含了吧?

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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