T
Ton van den Heuvel
Hi all,
why does the following code not compile, and fail with:
qed.cpp: In instantiation of `B<Foo*>':
qed.cpp:40: instantiated from here
qed.cpp:29: error: conflicting return type specified for `const T
B<T>::Test()
const [with T = Foo*]'
qed.cpp:14: error: overriding `virtual const Foo* A::Test() const'
------------------------
#include <iostream>
struct Foo {
int val;
};
class A {
public:
A( void ) {
}
virtual const Foo* Test( void ) const {
return NULL;
}
protected:
Foo foo;
};
template< class T >
class B : A {
public:
B( void ) {
}
const T Test( void ) const {
return NULL;
}
protected:
T foo;
};
int main( void ) {
A a;
B< Foo* > b;
}
-----------------------
I don't see a problem here. Both MSVC and GCC complain about the code
in a similar way, so there is a fundamental problem here, but I can't
figure out what the problem is. Any hints?
Regards,
Ton van den Heuvel
why does the following code not compile, and fail with:
qed.cpp: In instantiation of `B<Foo*>':
qed.cpp:40: instantiated from here
qed.cpp:29: error: conflicting return type specified for `const T
B<T>::Test()
const [with T = Foo*]'
qed.cpp:14: error: overriding `virtual const Foo* A::Test() const'
------------------------
#include <iostream>
struct Foo {
int val;
};
class A {
public:
A( void ) {
}
virtual const Foo* Test( void ) const {
return NULL;
}
protected:
Foo foo;
};
template< class T >
class B : A {
public:
B( void ) {
}
const T Test( void ) const {
return NULL;
}
protected:
T foo;
};
int main( void ) {
A a;
B< Foo* > b;
}
-----------------------
I don't see a problem here. Both MSVC and GCC complain about the code
in a similar way, so there is a fundamental problem here, but I can't
figure out what the problem is. Any hints?
Regards,
Ton van den Heuvel