求指点 关于extern

many2023 many2023 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我定义了三个类A,B,C。B中有一个A的对象ba,C通过extern A ba 使用B中的ba。但是出现这么一个错误
>3.obj : error LNK2001: 无法解析的外部符号 "class a ba" (?ba@@3Va@@A)
1>D:\many_c++\1231231\Debug\1231231.exe : fatal error LNK1120: 1 个无法解析的外部命令


代码如下:

1.h
#pragma once

class a
{
public:
a(){}
~a(){}
void fun(int i);

};
1.cpp
#include<iostream>
#include "1.h"
using namespace std;
void a::fun(int i)
{
cout<<i;
}
2.h
#pragma once
#include "1.h"
class b
{
public:
b();
~b(){}
a ba;
};
2.cpp
#include"2.h"

b::b()
{}
3.h
#pragma once

class c
{
public:
c();
~c(){}
void f();
};
3.cpp
#include "3.h"
#include "2.h"
#include "1.h"
extern a ba;
c::c()
{}

void c::f()
{
ba.fun(2);
}
4.cpp
#include "1.h"
#include "2.h"
#include "3.h"

int main()
{
b bb;
c cc;
cc.f();
return 0;
}
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
many2023
VC/MFC 16,550 成员 421,606 内容