S
Sebastian Schucht
Hi,
I have a templateclass with virtual member-functions, so i can't create
instances ... but for returning the result i would like use one. So i
replaced the A<TType> from the baseclass with the Type from the spezialized
class. After this, the error invalid covariant return type occoured.
the following minimal sample shows the problem:
#include <iostream>
class C{};
template<class TType>
class A
{
public:
virtual A<TType> operator+(const A<TType>& i_sum) = 0;
};
class B
ublic A<C>
{
public:
B operator+(const A<C>& i_sum) {return *this;};
};
main()
{
B a,b,c;
a+b;
}
After compiling with g++ version 4.1.2 (Ubuntu 4.1.2-0ubuntu4) i have the
following erros on screen:
mini.cpp:14: error: invalid covariant return type for 'virtual B
B:
perator+(const A<C>&)'
mini.cpp:8: error: overriding 'A<TType> A<TType>:
perator+(const
A<TType>&) [with TType = C]'
- Why is this an error?
- On wich way i can fix it?
Thank you for your help!
With best regards
Sebastian Schucht
--
B.Sc. Sebastian Schucht
Teichhausstraße 38
64287 Darmstadt
UIN: 260 121 043
skype: SebastianSchucht
I have a templateclass with virtual member-functions, so i can't create
instances ... but for returning the result i would like use one. So i
replaced the A<TType> from the baseclass with the Type from the spezialized
class. After this, the error invalid covariant return type occoured.
the following minimal sample shows the problem:
#include <iostream>
class C{};
template<class TType>
class A
{
public:
virtual A<TType> operator+(const A<TType>& i_sum) = 0;
};
class B
{
public:
B operator+(const A<C>& i_sum) {return *this;};
};
main()
{
B a,b,c;
a+b;
}
After compiling with g++ version 4.1.2 (Ubuntu 4.1.2-0ubuntu4) i have the
following erros on screen:
mini.cpp:14: error: invalid covariant return type for 'virtual B
B:
mini.cpp:8: error: overriding 'A<TType> A<TType>:
A<TType>&) [with TType = C]'
- Why is this an error?
- On wich way i can fix it?
Thank you for your help!
With best regards
Sebastian Schucht
--
B.Sc. Sebastian Schucht
Teichhausstraße 38
64287 Darmstadt
UIN: 260 121 043
skype: SebastianSchucht