C++ CLI abstract

Hi,

I am trying to make complex shape using StreamGeometry Class https://msdn.microsoft.com/en-us/library/system.windows.media.streamgeometry.aspx

and its definition says that it uses StreamGeometryContext Class which is abstract class https://msdn.microsoft.com/en-us/library/system.windows.media.streamgeometrycontext.aspx

I saw that on C# and other languages they just create StreamGeometryContext object. But how it is possible to create object of the class which is abstract?

Here is example:

var geometry = new StreamGeometry();
using (var context = geometry.Open())
{
bool isStroked = pen != null;
const bool isSmoothJoin = true;

context.BeginFigure(rect.TopLeft + new Vector(0, cornerRadius.TopLeft), brush != null, true);
context.ArcTo(new Point(rect.TopLeft.X + cornerRadius.TopLeft, rect.TopLeft.Y),
new Size(cornerRadius.TopLeft, cornerRadius.TopLeft),
90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);
context.LineTo(rect.TopRight - new Vector(cornerRadius.TopRight, 0), isStroked, isSmoothJoin);
context.ArcTo(new Point(rect.TopRight.X, rect.TopRight.Y + cornerRadius.TopRight),
new Size(cornerRadius.TopRight, cornerRadius.TopRight),
But how it is possible to create object of the class which is abstract?

You can't create objects from abstrct classes, but you can create a concrete class and store it in a pointer to abstract class.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <string>

using namespace std;

class Shape
{
public:
  virtual void Draw () = 0;
  virtual ~Shape (){}
};

class Circle : public Shape
{
  void Draw () {cout << "\nCircle::Draw()\n\n";}
};

int main ()
{
  Shape *shape = new Circle ();
  shape->Draw ();
  delete shape;
  system ("pause");
  return 0;
}


In the C# example you posted geometry.Open() will create a concrete class which inherits from StreamGeometry.
Topic archived. No new replies allowed.