This is the header file
GeomVisitor.h
// Forward declarations
class Rectangle;
class Font;
class GeomVisitor
{
public:
virtual ~GeomVisitor() = default;
virtual void visit(Rectangle&) { };
virtual void visit(Font&) { };
};
now in the cpp file i want to create different classes for different objects.
GeomObject.cpp
#include "GeomObject.h
// all other includes
class visitorRectangle : public GeomVisitor
{
private:
std::string variableName;
std::string variableValue;
public:
virtual void visit(Rectangle& rect)
{
if (variableName.compare("WIDTH") != 0)
rect.SetWidth(std::stof(variableValue));
if (variableName.compare("HEIGHT") != 0)
rect.SetHeight(std::stof(variableValue));
}
};
class visitorFont : public GeomVisitor
{
private:
std::string variableName;
std::string variableValue;
public:
virtual void visit(SumFont& fnt)
{
if (variableName.compare("TEXT") != 0)
fnt.setText(variableValue);
if (variableName.compare("USESHADOW") != 0)
fnt.setUseShadow(std::stoi(variableValue));
if (variableName.compare("FONTSIZE") != 0)
fnt.setFontSize(std::stoi(variableValue));
if (variableName.compare("SHADOWDISTANCE") != 0)
fnt.setShadowDistance(std::stof(variableValue));
}
};
The problem i am facing is how can i declare class visitorRectangle and class visitorFont as objects in other classes
Do i have to add the cpp files where i need to declare these classes as object varibles ?
Aucun commentaire:
Enregistrer un commentaire