【发布时间】:2026-01-02 12:45:01
【问题描述】:
以下代码被 VC++ 2013 接受,但被 clang 3.4 拒绝。
哪个编译器符合 C++ 标准?
template<class T>
struct A
{
T n;
};
template<class T>
struct B : A<T>
{
// VC++ 2013 : OK
// clang : error : use of class template 'A' requires template arguments
B& f1(const A& obj)
{
return *this;
}
// VC++ : OK
// clang : OK
B& f2(const A<T>& obj)
{
return *this;
}
};
int main()
{
B<int> b;
}
【问题讨论】:
-
请注意,g++ 也会发出错误 (coliru.stacked-crooked.com/a/38c78abd3f098143)。
-
看起来像是 language-lawyer 标签的主要候选者,但你已经 5 岁了...
标签: c++ templates visual-c++ clang standards