外部结构阵列 [英] extern with arrays of structure

查看:51
本文介绍了外部结构阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我试图在2个.cc文件之间共享一些数据,因此在其中一个.cc文件中将结构数组声明为extern。


但是我在原始数组条目中得到异常条目,否则我就没有了。


file1.h

- -------

struct Mylistdetails {

int id;

int value;

}



file1.cc

----------

struct Mylistdetails myList_ [MAX_NO] ;


file2.cc

-----------

#include< ; file1.h>


extern struct Mylistdetails myList_ [MAX_NO];



这里的目的是调用这些数组数据进入file2.Here,myList_ [i] .id和myList_ [i] .value只是一旦被声明为''extern''就意外。如果没有使用这个extern方法,只有在使用file2时才会观察到预期的值。 br />

你能否指出这个行为s。非常感谢您就如何解决这个问题提出的建议。

Hi,

I tried to share some data between 2 .cc files hence declared the arrays of structure as extern in one of the .cc files.

However I get abnormal entries in the original array entries otherwise I wouldn''t have got.

file1.h
---------
struct Mylistdetails {
int id;
int value;
}


file1.cc
----------
struct Mylistdetails myList_[MAX_NO];


file2.cc
-----------
#include <file1.h>

extern struct Mylistdetails myList_[MAX_NO];


The purpose here is to call these array data into the file2.Here,myList_[i].id and myList_[i].value are just unexpected once declared as ''extern''.If not used this extern method the expected values are observed once only file2 is being used.

Could you kindly specify the behaviour of this.Many thanks for your advise on how to tackle such a problem.

推荐答案

您的代码是否已编译?

有一个;缺少
did your code compile?
there is a ; missing in
展开 | 选择 | Wrap | 行号



您的代码是否已编译?

有一个;缺少
did your code compile?
there is a ; missing in
展开 | 选择 | Wrap | 行号



它不在当前目录中,所以我指定了路径

#include< direct / file1.h>


是的我尝试在exade文件中输入extern声明(file1.h) )。仍然无法工作。


感谢您的关注。
well it is not in the current directory, so i specified the path
#include <direct/file1.h>

Yes I tried putting extern declaration in the heade file too(file1.h).Still doesn''t work.

Thanks for your attention.



我猜你是在unix系统上,试试

I guess you are on a unix system, try

展开 | < span class =codeLinkonclick =selectAll(this);>选择 | Wrap | 行号


这篇关于外部结构阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆