使用不同的头类型在Ubuntu下编译
Compile under Ubuntu with different header type
我有三个文件,即"main.cpp"、"testclass.cpp"answers"testclass.h"。我通过调用编译这些文件
g++ testclass.cpp main.cpp
main.cpp
#include <iostream>
#include "testclass.hpp"
int main()
{
testclass foo(56);
std::cout << "Object in cppt" << numberobject.getNumber() << "n";
return 0;
}
测试类头
#ifndef TESTCLASS_H
#define TESTCLASS_H
class testclass
{
private:
int number;
public:
testclass();
testclass(int);
int getNumber();
};
#endif //TESTCLASS_H
testclass.cpp
#include "testclass.hpp"
testclass::testclass()
{
}
testclass::testclass(int number)
{
this->number = number;
}
int testclass::getNumber()
{
return number;
}
将出现编译错误
testclass.cpp:7:1: error: prototype for ‘testclass::testclass(int)’ does not match any in class ‘testclass’
testclass::testclass(int number)
^
testclass.h:4:7: error: candidates are: testclass::testclass(const testclass&)
class testclass
^
testclass.cpp:3:1: error: testclass::testclass()
testclass::testclass()
^
但是,如果我将"testclass.h"更改为"testclass.hpp",并将所有#include
语句从#include "testclass.h"
更改为#include "testclass.hpp"
,则效果良好。
为什么我不能编译.h文件?还有什么可以用.h文件编译的吗?
最后,我发现同一目录下有一个奇怪的"testobject.h.gch"文件。删除它后,它运行良好。
相关文章:
- 在 Ubuntu 18.04 上编译 GLSL 着色器时"不支持 GLSL 3.30"?
- 在 Ubuntu 中编译 SuiteSparse,在安装 CHOLMOD 时中断
- 如何在 Ubuntu 上编译 OpenGL 项目?
- 在 ubuntu 焦点上编译虚幻引擎 4.25 时出错
- 在 Ubuntu 16.04 LTS 上使用 c++ 编译问题?
- 编译问题与 Ubuntu Linux
- Ubuntu 下的 Cmake 和 Intel IPP 的编译问题
- 在Linux/Ubuntu中编译openCV应用程序时,如何解决未定义的引用cv:..?
- 如何解决我在 Ubuntu 19.04 下使用 GLFW 时遇到的这个编译问题?
- wxWebView在Ubuntu上的编译问题
- 如何在Ubuntu中使用Visual Studio代码编译C++代码
- 在 Ubuntu 18.04 上,我编译的 cpp 可执行文件找不到 VTK7 依赖项
- 在 Xubuntu 19.04 中编译 c++ 是否应该与在 Ubuntu 18.04 中编译 c++ 不同
- 针对 ubuntu 和 Mac 编译的差异
- G++ 编译:在 Ubuntu 18.04 上对 'ATL_<...>' 的未定义引用
- cmake cuda在Windows上单独的编译静态LIB链接错误,但在Ubuntu上没有
- 加密蛋白使编译问题Ubuntu
- Open AL 的函数在 ubuntu 中使用 g++ 编译时给出未定义引用的错误
- 拥有LLVM IR库如何从Ubuntu将其交叉编译到iOS,Android,Windows和Mac?
- C++ 在 minGW-W64 g++ 中编译的代码不能使用 Ubuntu g++ 编译