invalid covariant type / forward declaration?
Considering the following situation, is there a way to tell class White that
a Black* is actually a valid Base*? In other words can I somehow forward
declare "class Black : public Base;" in White.h and vice versa? Or am I
trying to do something very bad and clearly illegal? :)
TIA, Sybolt
// Base.h
#ifndef BASE_H
#define BASE_H
class Base {
public:
virtual Base *colleague(int i) const = 0;
virtual Base *opponent(int i) const = 0;
....
};
// White.h
#ifndef WHITE_H
#define WHITE_H
#include "Base.h"
class White : public Base {
public:
White *colleague(int i) const { return White::create(i); }
Black *opponent(int i) const { return Black::create(i); }
static White *create(int i);
....
};
// Black.h
#ifndef BLACK_H
#define BLACK_H
#include "Base.h"
class Black : public Base {
public:
Black *colleague(int i) const { return Black::create(i); }
White *opponent(int i) const { return White::create(i); }
static Black *create(int i);
....
};