小编Joj*_*ahl的帖子

为什么未使用的成员模板功能的类模板实例化失败

这有什么问题:

#include <type_traits>

struct A;

template<typename T>
struct B
{
    template<typename=std::enable_if<std::is_copy_constructible<T>::value>>
    void f1() {}
};

template<typename T>
struct C {};


// Type your code here, or load an example.
int main() {
    // Following fails
    B<A> b;
    // Could use this:
    // b.f1<C>();

    // This complies
    C<A> c;

    return 0;
}

/* This to be in or not doesn't make a difference
struct A
{};
*/
Run Code Online (Sandbox Code Playgroud)

我在这里尝试过:https : //godbolt.org/z/NkL44s,使用了不同的编译器:

  • x86-64 gcc 9.2:编译
  • x86-64 gcc(trunk):失败
  • x86-64 clang 6.0.0:编译
  • x86-64 …

c++ templates

5
推荐指数
1
解决办法
98
查看次数

标签 统计

c++ ×1

templates ×1