求指点 关于extern
我定义了三个类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;
}