How can I write a method toDerived()
(instead or additionally to a constructor) that converts a base class object to a derived class object?
With the following setup I get the error "Incomplete result type 'Derived' in function definition of 'toDerived()'".
// base.h
#ifndef BASE_H
#define BASE_H
#include "derived.h"
class Derived;
class Base {
public:
// constructor etc.
Derived toDerived() const { /* ... */ };
};
#endif
// derived.h
#ifndef DERIVED_H
#define DERIVED_H
#include "base.h"
class Derived : public Base {
public:
// constructor etc.
};