prog.cpp:32:3: error: invalid use of incomplete type 'struct Cloneable'
prog.cpp:4:2: error: forward declaration of 'struct Cloneable'
prog.cpp: In function 'int main()':
prog.cpp:94:27: error: cannot declare variable 'a' to be of abstract type 'MyImplementationClass'
prog.cpp:71:1: note: because the following virtual functions are pure within 'MyImplementationClass':
prog.cpp:13:22: note: virtual Cloneable* Cloneable::Clone() const
prog.cpp:19:16: note: virtual void Cloneable::ReleaseClone()
prog.cpp:97:30: error: no matching function for call to 'Cloneable::ReleaseClone(MyAbstractClass*&)'
prog.cpp:14:15: note: candidates are: static void Cloneable::ReleaseClone(Cloneable*&)
prog.cpp:19:16: note: virtual void Cloneable::ReleaseClone()
prog.cpp: In member function 'ICT* Cloneable::Auto<InheritingClass>::Clone() const
[with InheritingClass = MyImplementationClass, ICT = MyImplementationClass]':
prog.cpp:95:34: instantiated from here
prog.cpp:41:22: error: cannot allocate an object of abstract type 'MyImplementationClass'
prog.cpp:71:1: note: since type 'MyImplementationClass' has pure virtual functions
I'm clearly stating that I am using the function implementations from Cloneable::Auto, but it still thinks that MyImplementationClass is abstract and has not implemented those functions. I also don't understand the first errors about Cloneable being incomplete...
I wrote all this code myself so I probably went about it in the wrong way, but this is what I had hoped worked, because otherwise this will be a nightmare to implement.
I also don't understand the first errors about Cloneable being incomplete...
To quote clang++, whose compiler diagnostics make more sense:
test.cc:31:32: error: base class has incomplete type
struct Auto : public virtual Cloneable
~~~~~~~~~~~~~~~^~~~~~~~~
test.cc:3:12: note: definition of 'Cloneable' is not complete until the closing
'}'
struct Cloneable
^
prog.cpp: In instantiation of 'Cloneable::Auto<MyImplementationClass>':
prog.cpp:75:1: instantiated from here
prog.cpp:41:34: error: invalid covariant return type for 'InheritingClass* Cloneable::Auto<InheritingClass>::Clone() const
[with InheritingClass = MyImplementationClass]'
prog.cpp:13:28: error: overriding 'virtual Cloneable* Cloneable::Clone() const'
I'd like to know how to fix it, because otherwise it means I have to use a dynamic_cast on the clone function provided by Cloneable::Auto to get back down to the correct type - very ugly and unintuitive. It could be avoided if I implemented the clone function manually, but then what is the point of the automagical class that is supposed to do that for me?