S
S
sinoptis2018-09-28 10:48:51
OOP
sinoptis, 2018-09-28 10:48:51

Inheritance from a purely abstract class. Not included?

#pragma once
#include "Vector.h"
class AbstractFigure
{
public:
  virtual void Scale() = 0;
  virtual void Rotate() = 0;
  virtual void Move(Vector direction) = 0;
};

#pragma once
#include "AbstractFigure.h"
class Point :
  public AbstractFigure
{
public:
  Point();
  ~Point();

  // Inherited via AbstractFigure
  virtual void Scale() override;
  virtual void Rotate() override;
  virtual void Move(Vector direction) override;
};

#pragma once
#include "AbstractFigure.h"
class Vector :
  public AbstractFigure
{
public:
  Vector();
  ~Vector();

  // Inherited via AbstractFigure
  virtual void Scale() override;
  virtual void Rotate() override;
  virtual void Move(Vector direction) override;
};

Errors C2504 'AbstractFigure': base class undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-09-28
@sinoptis

#pragma once
#include "Vector.h"
class AbstractFigure
...
#pragma once
#include "AbstractFigure.h"
class Vector :
public AbstractFigure
...
No, it won't. Because either AbstractFigure.h is the first one, or Vector.h, someone will be out of luck.
You can fix it like this:
#pragma once
class Vector;
class AbstractFigure
{
public:
  virtual void Scale() = 0;
  virtual void Rotate() = 0;
  virtual void Move(const Vector& direction) = 0;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question