class A
{
// is abstract
};
class B : public A
{
// ...
};
class C : public A
{
// ...
};
template<class T> class Foo
{
public:
Foo() {}
virtual ~Foo() { delete _obj; }
void createObj() { if ( !_obj ) _obj = new T; }
A* getObj() const { return _obj; }
template<class U>
Foo<T>& operator=(const Foo<U>& other)
{
// ...
return *this;
}
private:
A* _obj;
};
class FooC;
class FooB : public Foo<B>
{
public:
FooB() {}
virtual ~FooB() {}
FooB& operator=(const FooC& other)
{
Foo<B>::operator=( static_cast< Foo<C> > other); // NOK
// compiler doesnt yet know that FooC is derived from Foo<C>
return *this;
}
};
class FooC : public Foo<C>
{
FooC() {}
virtual ~FooC() {}
FooC& operator=(const FooB& other)
{
Foo<C>::operator=(other); // OK
return *this;
}
};
int main(int argc, char* argv[])
{
}
main3.cpp: In member function ‘FooB& FooB::operator=(const FooC&)’:
main3.cpp:46:44: error: expected ‘(’ before ‘other’
main3.cpp:46:49: error: no matching function for call to ‘Foo<C>::Foo(const FooC&)’
main3.cpp:46:49: note: candidates are:
main3.cpp:19:2: note: Foo<T>::Foo() [with T = C]
main3.cpp:19:2: note: candidate expects 0 arguments, 1 provided
main3.cpp:16:25: note: Foo<C>::Foo(const Foo<C>&)
main3.cpp:16:25: note: no known conversion for argument 1 from ‘const FooC’ to ‘const Foo<C>&’