std::make_unsigned损坏/链接错误

std::make_unsigned mangling/linking error

本文关键字:链接 错误 损坏 unsigned make std      更新时间:2023-10-16

我正试图做一些类似的事情

template<class T>
void foo(typename std::make_unsigned<T>::type x)
    {
    //do a lot with x (do not want to repeat for signed vs unsigned)
    }
template<class T>
void foo(T x)
    {
    if(x < 0)
        {x=-x;}
    foo<typename std::make_unsigned<T>::type>
        (static_cast<typename std::make_unsigned<T>::type >(x));
    }

当我尝试使用强制显式实例化(extern templates)时,我从nm得到以下解映射输出:

void foo<unsigned long long>(std::make_unsigned<unsigned long long>::type)

现在,为什么std::make_unsigned::type不发出与我写的无符号T显式相同的类型?相反,我得到了未定义的引用。

我认为不允许显式初始化/加密成员。但我找不到确切的c++参考。