- 论坛徽章:
- 0
|
test1.cpp和test2.cpp在同一个工程里面 ,
在test1.cpp中声明的对象
- MyClass myclass1(100);
- void functest1(){
- int arry1[5]={1,2,3,4,5};
- for(int i=0;i<5;i++)
- myclass1.p[i]=arry1[i];
- }
复制代码
要在test2.cpp中访问对象myclass1,该怎么处理?
- void functest2(){
- int arry2[5]={0};
- for(int i=0;i<5;i++)
- arry2[i]=myclass1.p[i];
- }
复制代码
我用下面2种方法处理都不行:
1,我在test2.cpp中声明extern MyClass myclass1;
但是myclass1.p的值不等于123,而是0,为啥?
2,我在test2.cpp中声明extern MyClass myclass1(100);
fatal error LNK1169: one or more multiply defined symbols found 为啥?
[ 本帖最后由 light511 于 2009-7-13 11:03 编辑 ] |
|