2 回答
You can not create objects of type SomeInterface::reference
, since it is a pure abstract class, and that is what the compiler told you.
You need to return a reference (or a pointer) to such class. Like this :
virtual reference& operator[](unsigned int pos) = 0;
but then :
- in derived classes, you shouldn't change the signature of the pure virtual methods. It should stay
virtual SomeInterface::reference& operator[](unsigned int pos)
- you can not return reference to a temporary object
btw take care how you create objects of such classes. They do not have virtual destructors.
Basically you can't return a reference to something that can never exist. However, you could use a pointer to an abstract class. That pointer will ultimately only be able to point to an instance of a derived class.
It is not clear exactly what you are trying to do. But you might look into Creation Patterns to find something close to what you need