Re: Invalid C++ or bug in GCC 4.8
On 2013-07-01 13:22, marcel.loose@googlemail.com wrote:
You cannot create an object of an abstract class type, so there
cannot be a function with such return type. The compiler error
message is completely reasonable here.
So, if I understand things correctly, the fix is easy. Instead of
class ObjectFactory<Base (), TypeId> { };
// ...
typedef ObjectFactory< Abstract(), int> MyFactory;
I should write
class ObjectFactory<Base* (), TypeId> { };
// ...
typedef ObjectFactory< Abstract* (), int> MyFactory;
Alternatively you could also write:
class ObjectFactory<Base& (), TypeId> { };
// ...
typedef ObjectFactory< Abstract& (), int> MyFactory;
I always thought that the part between the angle brackets
represented the signature of the class' constructor, instead of the
return type.
In C++ the term "signature" has a very specific meaning, except for
function templates (or specializations thereof) it does *not* contain
the return type. Furthermore, there is no way to describe the type of
a constructor as a function type directly. Actually, constructors have
not a well-defined return type at all, the nearest approximation to
this would be a void return type.
In addition, your association of T() (for some type T) referring to a
constructor call is based on an *expression* T(), but in your example,
'Base()' and 'Abstract()' are not expressions, they are function
types.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]