使用GCC编译类
Compiling a Class with GCC
嘿,我不确定我是否犯了语法错误,但我犯了一个类,当我试图编译它时得到了这个错误…
dining.h:7:1: error: unknown type name ‘class’
dining.h:7:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
它与g++配合使用很好,但我必须使用gcc。。。
这是问题代码。。
#ifndef DINING_H
#define DINING_H
class DiningSet {
public:
DiningSet();
~DiningSet();
void getSize(); // accepts X and Y dimentions of the table (in metres)
//void surfaceArea(int,int); // Calculates Surface Area of table (in square metres)
void numChairs(); // accepts number of chairs
void cushionColour(); // accepts a cushion colour
void woodType(); // accepts wood type
void priceComp(); // computes a price of set
void purchaseDet(); // displays details of purchase
void purchasePrice(); // displays price of purchace
private:
int X, Y; // Dimentions of table
float Surface;
int chairs; // Number of chairs
char colour; // colour of cushion (should be dynamic array)
char wood;
float totalPrice;
};
#endif
gcc
默认将程序编译为C。由于它是C++程序,因此无法正常工作。使用-x c++
标志,或者将文件重命名为具有.C
(大小写很重要)或.cpp
扩展名。
编辑:实际上,你可以使用一大堆文件扩展名来表示你的程序是C++。从这个链接:
.cc、.cp、.cxx、.cpp、.c++、.c
编辑2:你下面的评论让我觉得你试图把头文件放在命令行上。不要那样做。只需编译源文件,并根据需要包含标头。
相关文章:
- 为什么 gcc 编译这个而 msvc 没有
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- GCC,CMake,预编译标头和维护依赖项
- GCC 8.3 无法编译 std::bind_front
- Clang不会编译GCC会编译的模板专业化
- 使用交叉工具ng编译gcc时出错
- 编译 GCC-5.0 OS X 狮子 dyld:找不到符号:__ZNKSt11logic_error4whatEv
- 在类中将不完整类型的unique_ptr初始化为 nullptr 时编译 gcc 错误
- 除了 Linux 上的源代码和编译 (GCC) 之外,有没有办法在 Windows 中托管 IDE
- 在 64 位 debian 上编译 GCC 的代码可视化补丁
- 编译gcc 4.6.4中的boost::move
- 模板编译:gcc vs VS2010
- C++ 使用编译器编译"gcc"简单文件
- 如何从php编译GCC
- 在 Visual Studio 中编译 gcc 代码会导致错误 C3646:"__attribute__":未知的覆盖说明符
- 在windows上编译gcc 4.7
- 在Vortex86DX上从头开始构建和编译GCC 5.2.0时出错
- 在编译GCC时出错部分模板专门化,而不是MSVC
- GLM Math lib 编译 GCC 错误
- Synology交叉编译GCC -std=c++0x