Hey I have an abstract class named Partition which is a functor, and its a member of my ConcavePolygon class. The Partition Functor depends on a lot of the ConcavePolygon's data such as TPPLPoints and SFMLPoints.
I've found that even though i've defined the class inside the one it depends on, i can't easily reach Concaves's data. How do i do this?
I also want to use some functions from the Body class, and hoped to do that through ConcavePolygon since its a descendent from it. (needs the AddShape() function);
here's the code if it's helpful:
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{
protected:
virtual void RunAlgorithm(){};
public:
Partition(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++){
TPPLPoints.push_back(TPPLPoint(Points[I].x, Points[I].y));
SFMLPoints.push_back(Points[I]);}
TPPLPoly Poly(&TPPLPoints[0], numbPoints, false);
//clear everything to be filled with the Partition Algorithm
this->Clear();
// Run the Partitioning Algorithm
RunAlgorithm();
// 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);
this->AddShape(TempShape);
}
};
};
class Convexulate: public Partition{
bool RunAlgorithm(TPPLPoly& Poly, std::list<TPPLPoly>& PartitionOutput){
TPPLPartition Partition;
Partition.ConvexPartition_OPT(&Poly, &PartitionOutput);
};
};
class Triangulate: public Partition{
bool RunAlgorithm(TPPLPoly& Poly, std::list<TPPLPoly>& PartitionOutput){
TPPLPartition Partition;
Partition.Triangulate_OPT(&Poly, &PartitionOutput);
};
};
//////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////// Constructors /////////////////////////////////////////////////////
ConcavePolygon(Vector2f* Points, long numbPoints){
Convexulate(Points, numbPoints);
};
};// ConcavePolygon Class
In C++, nested classes are really just a way of scoping namespaces (and providing protection: public/protected/private) for class names. They do not create any special relationship between the two classes besides the name: OuterClass::NestedClass.
So you need to treat nested classes like they are separate classes. If you want the NestedClass to get access to the private members of the OuterClass, you must explicitly declare it a friend of the OuterClass. If you want the NestedClass to access a particular instance of an OuterClass, you must give it an instance of the OuterClass.