私はいくつかの幾何学的形状のための小さなライブラリを作成しています。そうするために、私はプロトタイプをshapes.h
ファイルに書き出し、メソッドはshapes.cpp
ファイルに書きます。 これはヘッダーです:不明なタイプ名 'クラス'
#ifndef __shapeslib
#define __shapeslib
class Shape{
protected:
struct dimensions{
double heigth;
double width;
};
double radius; // for circle class to be inherited
public:
Shape(double heigth, double width); // Constructor
Shape(const Shape & shape); // copy constructor for class
~Shape(); // Destructor
virtual double area(double heigth, double width);
virtual double perimeter(double heigth, double width);
void height();
void width();
double rotate(double heigth, double width);
};
しかし、Atomのソフトウェアでファイルを保存するとき、私はラインclass Shape{
unknown type name 'class'
expected ';' after top level declarator
のためにこれらの2つのエラーを取得し、私はその可能性hereを読みます私がC++ではなくCでコンパイルしているからです。私は心からこのことを避ける方法はまだ考えていません(まだ初心者です)。
また、ファイル名を.h
から.hpp
に変更しようとしましたが、動作しているようです。残念ながら、.h
ヘッダーファイルが必要です。
フィードバックは本当にありがとうございます。 ありがとうございます。
Cには「クラス」はありません。 –
はい、同意します。しかし、このコードはC++用です(またはそうすべきです)。 –
gccでコンパイルする場合は、g ++でコンパイルしてみてください。 – OutOfBound