Я работаю над программой cpp, используя абстрактные классы.Видимо, компилятор не принимает тот факт, что я объявил абстрактный класс и производный.У меня есть разные файлы (.cpp и .h).Это следующие ошибки:
1> IGeomObj.obj: ошибка LNK2005: «public: virtual void __thiscall IGeomObj :: circleference (void)» (?
1> main.obj: ошибка LNK2001: неразрешенный внешний символ "public: virtual void __thiscall GeoRect :: circleference (void)" (? Circleference @ GeoRect @@ UAEXXZ)
1> IGeomObj.exe: фатальная ошибка LNK1120: 1 неразрешенная внешняя версия ========== Построение: 0 выполнено, 1 не выполнено, 0 обновлено, 0 пропущено ==========
А вот код: main ()
# include <iostream>
# include "IGeomObj.h"
# include "GeoCircle.h"
# include "GeoEllipse.h"
# include "GeoRect.h"
# include "GeoSquare.h"
# include "GeoTriangle.h"
using namespace std;
int main()
{
/*GeoSquare *R;
GeoTriangle *R;
GeoRect *R;
GeoRect *R;*/
int opt;
do{
cout<<endl<<"Menu:"<<endl<<endl<<"0. Exit"<<endl<<"1. New rectangle"
<<endl<<"2. New Square"<<endl<<"3. New Triangle"<<endl<<"4. New Circle"<<endl
<<"5. New Ellipse"<<endl;
cin>>opt;
switch(opt)
{
case 0:
break;
case 1:
GeoRect *R=new GeoRect;
cout<<endl<<"Height of the rectangle: ";
cin>>R->h;
cout<<endl<<"Width of the rectangle: ";
cin>>R->b;
R->output();
break;
};
}while(opt!=0);
system("pause");
return 0;
}
IGeomObj.h
#pragma once
#ifndef IGEOMOBJ_H
#define IGEOMOBJ_H
#include <iomanip>
#include <fstream>
class IGeomObj{
public:
float b,h,r,f,u;
virtual void output()=0;
virtual void area()=0;
virtual void circumference()=0;
};
#endif
IGeomObj.cpp
#include "IGeomObj.h"
#include <iostream>
using namespace std;
void IGeomObj::output(){};
void IGeomObj::area(){};
void IGeomObj::circumference(){};
GeoRect.h
#pragma once
#ifndef GEORECT_H
#define GEORECT_H
#include <iomanip>
#include <fstream>
#include "IGeomObj.h"
class GeoRect:public IGeomObj
{
public:
virtual void output();
virtual void area();
virtual void circumference();
};
#endif
GeoRect.cpp
#include "GeoRect.h"
#include <iostream>
using namespace std;
void GeoRect::output()
{
cout<<"Rectangle Area: "<<this->f<<" Circumference: "<<this->u;
};
void GeoRect::area()
{
this->f=this->h*this->b;
};
void IGeomObj::circumference()
{
this->u=2*this->h+2*this->b;
};