【发布时间】:2011-07-16 03:34:38
【问题描述】:
嘿,所以我正在尝试构建 ConcavePolygon 类的以下成员仿函数,但由于某种原因,我遇到了链接器外部符号错误:
未解析的外部符号“public: virtual void __thiscall sf::ConcavePolygon::Partition::RunAlgorithm(类 TPPLPoly &,类 std::list > &)"
我的目标是简单地创建一个包含 SFML (lib) 可以理解的图形数据的类,以及对图形数据进行分区或三角剖分的功能(多边形)
而不是用非常相似的代码编写两个大函数;一个用于三角化,一个用于做我所说的凸形,我决定尝试使用函子,并制作了基本函子Partition,带有后裔三角化和凸形。
基类Partition只包含两个函数:
- 包含所有功能的构造函数
- RunAlgorithm 函数(与构造函数分开,因此它可以被后代重载)
我认为该错误与虚拟 RunAlgorithm 函数有关,因为它依赖于构造函数,但我猜测它被后代以某种方式呈现为无效。
我该怎么做才能实现我的目标或解决这个问题?
代码如下:
class ConcavePolygon : public Body{
protected:
std::list<Vector2f> SFMLPoints;
std::vector <TPPLPoint> TPPLPoints; //TODO: figure out how to make a temp version without Memory Exception
public:
//////////////////// Partitioning/Triangulating Classes /////////////////////////////////////////////////////////////
class Partition{
public:
virtual void RunAlgorithm(TPPLPoly& Poly, std::list<TPPLPoly>& PartitionOutput);
Partition(){};
Partition(ConcavePolygon* Poly, Vector2f* Points, long numbPoints){ //TODO turn this into a base class for triangulate or Convexulate
//rev up all the needed data structs
std::list<TPPLPoly> PartitionOutput;
std::list <TPPLPoly> ::iterator I;
//Backup the points, and convert them to tppl
for(int I=0; I<numbPoints; I++){
Poly->TPPLPoints.push_back(TPPLPoint(Points[I].x, Points[I].y));
Poly->SFMLPoints.push_back(Points[I]);}
TPPLPoly TempPoly(&Poly->TPPLPoints[0], numbPoints, false);
//clear everything to be filled with the Partition Algorithm
Poly->Clear();
// Run the Partitioning Algorithm (This is an abstract function, and is overloaded)
RunAlgorithm(TempPoly, PartitionOutput);
// Convert results to SFML points, shapes, and add to the body
for( I= PartitionOutput.begin(); I!= PartitionOutput.end();I++){
sf::Shape TempShape;
for(int i=0; i< I->GetNumPoints(); i++)
TempShape.AddPoint( I->GetPoint(i).x, I->GetPoint(i).y);
Poly->AddShape(TempShape);
}
};
};
class Convexulate: public Partition{
public:
Convexulate(ConcavePolygon* Poly, Vector2f* Points, long numbPoints){
Partition(Poly, Points, numbPoints);};
void RunAlgorithm(TPPLPoly& Poly, std::list<TPPLPoly>& PartitionOutput){
TPPLPartition Partition;
Partition.ConvexPartition_OPT(&Poly, &PartitionOutput);
};
};
class Triangulate: public Partition{
public:
Triangulate(ConcavePolygon* Poly, Vector2f* Points, long numbPoints){
Partition(Poly, Points, numbPoints);};
void RunAlgorithm(TPPLPoly& Poly, std::list<TPPLPoly>& PartitionOutput){
TPPLPartition Partition;
Partition.Triangulate_OPT(&Poly, &PartitionOutput);
};
};
////////////////////// Constructors /////////////////////////////////////////////////////
ConcavePolygon(Vector2f* Points, long numbPoints){
Convexulate(this,Points, numbPoints);
};
};// ConcavePolygon Class
【问题讨论】:
标签: c++ polymorphism virtual linker-errors functor