Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;-未定义对<;函数名>;使用多个头文件时 我对C++编程很陌生,我已经在这个问题上学习了几个小时。_C++_Header - Fatal编程技术网

c++;-未定义对<;函数名>;使用多个头文件时 我对C++编程很陌生,我已经在这个问题上学习了几个小时。

c++;-未定义对<;函数名>;使用多个头文件时 我对C++编程很陌生,我已经在这个问题上学习了几个小时。,c++,header,C++,Header,我有三个头文件:A.h、B.h和common.h,还有两个.cpp文件:A.cpp、B.cpp A.h B.h A.cpp 错误:未定义对“AA::fun()”的引用 为什么我会犯这个错误?有人能解释一下吗? 非常感谢。如何构建应用程序?您是使用所有源文件构建,还是使用源文件生成的所有对象文件构建声明了一个全局变量,它与main函数中同名的局部变量非常不同。我在代码块中使用gcc c c++11编译器构建了该变量。即使没有在b.h中包含common.h,我也会出现此错误。是否所有源文件都列为项目

我有三个头文件:A.h、B.h和common.h,还有两个.cpp文件:A.cpp、B.cpp

A.h B.h A.cpp 错误:未定义对“AA::fun()”的引用

为什么我会犯这个错误?有人能解释一下吗?
非常感谢。

如何构建应用程序?您是使用所有源文件构建,还是使用源文件生成的所有对象文件构建声明了一个全局变量,它与
main
函数中同名的局部变量非常不同。我在代码块中使用gcc c c++11编译器构建了该变量。即使没有在b.h中包含common.h,我也会出现此错误。是否所有源文件都列为项目列表中的源文件?仅仅存在于磁盘上是不够的,您需要在实际的项目树中包含它们。
#ifndef A_H
#define A_H

#include"B.h"

class AA{
    public:
        void fun();
};

#endif
#ifndef B_H
#define B_H
#include <iostream>
#include "common.h"

using namespace std;

class BB{
    public: 
        void fun2();
};
#endif
extern int c;
#include "A.h"


void AA::fun(){
    cout<<"A"<<endl;
}
#include "B.h" 

void BB::fun2(){
    cout<<"FUN 2"<<endl;
}
#include "A.h"

int main(){
    int c = 5;
    AA a;
    a.fun();

    return 0;
}