簡単なクラス ライブラリを作成する必要があります。との 2 つのクラスがElement
ありPermutation
ます。
ファイル Element.h
#ifndef ELEMENT_H
#define ELEMENT_H
class Element
{
public:
virtual ~Element()=0;
virtual bool IsEven()=0;
virtual bool IsNeutral()=0;
};
#endif
ファイル順列.h
#ifndef PERMUTATION_H
#define PERMUTATION_H
#include "Element.h"
class Permutation: public Element
{
private:
int* numbers;
public:
const int k;
Permutation(const int, int*);
Permutation(const int);
Permutation();
~Permutation();
int NumberOfInversions();
bool IsEven();
bool IsNeutral();
friend Permutation operator+(const Permutation&, const Permutation&);
friend Permutation operator-(const Permutation&);
};
#endif
そして、クラス Permutation を実装する Permutation.cpp があります。クラス要素は抽象的であるため、実現された .cpp ファイルはありません。そこで、クラス Permutation を使用する簡単なテスト プログラム (main を含む) を書きたいと思います。プロジェクトをどのようにビルドすればよいですか? Linux プラットフォームで g++ コンパイラを使用しています。
動作しない Makefile は次のとおりです。
all: permutation_test
permutation_test: fuf.o Permutation.o
g++ fuf.o Permutation.o -o permutation_test
fuf.o: fuf.cpp
g++ -c fuf.cpp
Permutation.o: Permutation.cpp
g++ -c Permutation.cpp
clean:
rm -rf *o permuatation_test
(fuf.cpp には main メソッドが含まれています。)
エラー:
Permutation.o: 関数内 «Permutation::Permutation(int, int*)»:
Permutation.cpp:(.text+0xd): 未定義の参照 «Element::Element( )»
Permutation.o: 関数内 «Permutation::Permutation(int)»:
Permutation.cpp:(.text+0x3c): 未定義参照 «Element::Element()»
Permutation.cpp:(.text+0xac):未定義参照 «Element::~Element()»
Permutation.o: 関数内 «Permutation::Permutation()»:
Permutation.cpp:(.text+0xcd): 未定義参照 «Element::Element()»
Permutation.o : 関数内 «Permutation::~Permutation()»:
Permutation.cpp:(.text+0x11e): 未定義の参照 «Element::~Element()»
collect2: エラー: ld が 1 終了ステータスを返しました
それは今動作します。返信ありがとうございます。クラスElementの純粋な仮想デストラクタを仮想および削除されたコンストラクタに置き換えました