"Dog"クラスの内部にインターフェイスを実装したいのですが、次のエラーが発生しています。最終的な目的は、同等のオブジェクトを受け取る関数を使用して、オブジェクトの実際のインスタンスを、equalsのようにパラメータで渡すものと比較できるようにすることです。オペレータのオーバーロードは、そのインタフェースを実装する必要があるため、オプションではありません。 "new"キーワードを使用してオブジェクトを作成すると、エラーが発生します。C++エラーで抽象クラスをインスタンス化できません
"エラー2エラーC2259: '犬は':プロジェクト\ Visual Studioの2008 \ \ユーザー\フェニックス\ドキュメント\インターフェース・テスト\インターフェイステスト\インターフェイス-TEST.CPP 8:抽象クラスCをインスタンス化することはできません"ここが関与するクラスのコードです:
#pragma once
class IComp
{
public:
virtual bool f(const IComp& ic)=0; //pure virtual function
};
#include "IComp.h"
class Dog : public IComp
{
public:
Dog(void);
~Dog(void);
bool f(const Dog& d);
};
#include "StdAfx.h"
#include "Dog.h"
Dog::Dog(void)
{
}
Dog::~Dog(void)
{
}
bool Dog::f(const Dog &d)
{
return true;
}
#include "stdafx.h"
#include <iostream>
#include "Dog.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Dog *d = new Dog; //--------------ERROR HERE**
system("pause");
return 0;
}
ありがとうございました。 – HoNgOuRu