我相信以下内容应该编译和链接,但不是:
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; }
编译器输出:
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;
如果我在两个地方都删除了__restrict__
限定符,它会编译和链接。我究竟做错了什么?
笔记:
- 这是关于限制限定符和模板的唯一问题(截至撰写本文时)。有趣,不是吗?
- 我将 GCC 4.9.3 与
--std=c++11
.