我正在尝试为我的项目之一开发抽象设计模式代码,如下所示。.但是,我无法编译该代码..给了一些编译错误(如“ Unresolved external symbol ” public:virtual void __thiscall Xsecs::draw_lines (double,double)“(?draw_lines @ Xsecs @@ UAEXNN @ Z)”)。任何人都可以帮我这个忙...
#include "stdafx.h"
#include <iostream>
#include <vector>
#include "Xsecs.h"
using namespace std;
//Product class
class Xsecs
{
public:
virtual void draw_lines(double pt1, double pt2);
virtual void draw_curves(double pt1, double rad);
};
class polyline: public Xsecs
{
public:
virtual void draw_lines(double pt1,double pt2)
{
cout<<"draw_line in polygon"<<endl;
}
virtual void draw_curves(double pt1, double rad)
{
cout<<"Draw_curve in circle"<<endl;
}
/*void create_polygons()
{
cout<<"create_polygon_thru_draw_lines"<<endl;
}*/
};
class circle: public Xsecs
{
public:
virtual void draw_lines(double pt1,double pt2)
{
cout<<"draw_line in polygon"<<endl;
}
virtual void draw_curves(double pt1, double rad)
{
cout<<"Draw_curve in circle"<<endl;
}
/*void create_circles()
{
cout<<"Create circle"<<endl;
}*/
};
//Factory class
class Factory
{
public:
virtual polyline* create_polyline()=0;
virtual circle* create_circle()=0;
};
class Factory1: public Factory
{
public:
polyline* create_polyline()
{
return new polyline();
}
circle* create_circle()
{
return new circle();
}
};
class Factory2: public Factory
{
public:
circle* create_circle()
{
return new circle();
}
polyline* create_polyline()
{
return new polyline();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
Factory1 f1;
Factory * fp=&f1;
return 0;
}
最佳答案
我想您正在尝试创建虚拟基类。您需要在Xsecs类的draw_lines和draw_curves方法的末尾添加“= 0”
class Xsecs
{
public:
virtual void draw_lines(double pt1, double pt2) = 0;
virtual void draw_curves(double pt1, double rad) = 0;
};
编译器在提示,因为您还没有任何相关方法的实现。