A derived class of a base class that functions as an abstract class

I defined a superclass element. There is some derived class elementsay triangle, quadand cube. Some of the objects elementare boundary elements. If it elementis a boundary element, then I have to define additional data members and functions. I could easily get a class boundary_elementif the class is elementnot a base class. (I meant that if triangle, quadand cubeare separate classes, I can define separate derived classes, such as boundary_triangle, boundary_quadand boundary_cube).

So my problem is that I have to define a subclass boundary_elementthat should be the base (or even abstract) class to define the derived classes boundary_quad, boundary_triangleand boundary_cube.

How is this possible in C ++? can anyone suggest any architecture that serves the purpose?

Another way to solve my problem according to my logic is to define a class as shown below:

class boundary_element
{    
    element* m_boundary_elem;  
    //data members needed for quad,triangle and cube
    public:
    boundary (element*);
    //functions for modifying data of triangle,cube,quad.

}

A pointer is elementdefined as a member variable of another class. How can I restructure this class efficiently using inheritance. (i.e. use it as an abstract class to get classes boundary_triangle, boundary_quadand boundary_cube)

, , , , , . , .

+4
2

++ , Element Boundary .

- :

class Element {
};

class Boundary {
};

class Triangle : public Element {
};

class BoundaryTriangle : public Triangle, public Boundary {
};

. . .
+3

++?

, .

- , ?

- :

  • class AbstractShape {
         boundary getBoundary() const = 0;
         void draw(OutputScreen& screen) const = 0;
    };
    
  • ,

    Triangle : public AbstractShape {
        // Implement the triangle specifics   
    };
    
    Rectangle : public AbstractShape {
        // Implement the rectangle specifics   
    };
    
    Circle : public AbstractShape {
        // Implement the circle specifics   
    };
    
+1

Source: https://habr.com/ru/post/1668818/


All Articles