The following should, I believe, compile and link, but doesn't:
template<class S>
class A {
public:
virtual int foo(S arg) = 0;
virtual ~A() { }
};
class B : public A<int* __restrict__>
{
public:
int foo(int* __restrict__ arg) override { return 0; }
};
int main() { B b; }
The compiler output:
d9.cpp:11:6: error: ‘int B::foo(int*)’ marked override, but does not override
int foo(int* __restrict__ arg) override { return 0; }
^
d9.cpp: In function ‘int main()’:
d9.cpp:14:16: error: cannot declare variable ‘b’ to be of abstract type ‘B’
int main() { B b; }
^
d9.cpp:8:7: note: because the following virtual functions are pure within ‘B’:
class B : public A<int* __restrict__>
^
d9.cpp:4:14: note: int A<S>::foo(S) [with S = int* __restrict__]
virtual int foo(S arg) = 0;
If I remove the __restrict__
qualifier in both places, it does compile and link. What am I doing wrong?
Notes:
- This is the only question on SO (as of the time of writing) regarding both the restrict qualifier and templates. Funny, isn't it?
- I'm using GCC 4.9.3 with
--std=c++11
.