0

为什么这段代码不起作用:

template <typename valueType>
struct ts
{
    inline ts( valueType v )
    {}
};

template <typename charType>
inline void test( ts <charType> str )
{}

void testfun( void )
{
    test( 1 ); // ERROR: ts <typename valueType> not deducible from int
}

但是这个呢?

void testfun( void )
{
    ts a = 1; // OK: ts <typename valueType> is ts <int> because constructor
}

在这两种情况下,我们都在处理 ts 模板,但在第一种情况下,它是作为函数参数的嵌入式模板实例化,而在第二种情况下,模板是直接推导出来的。请详细说明使用 C++20 标准的参数。

4

0 回答 0