小编Rob*_*t D的帖子

内部类中的通用复制构造函数

我想指定转换A<T>::BA<U>::B.

template<typename T>
struct A
{
    struct B
    {
        B() {}

        template<typename U>
        B(const typename A<U>::B& rhs) {}
    };
};

int main()
{
    A<int>::B x;
    A<double>::B y = x;
}
Run Code Online (Sandbox Code Playgroud)

我以为这会这样做,但我得到编译器错误:

从'A <int> :: B'转换为非标量类型'A <double> :: B'request"

为什么我的代码不正确,以及实现所需转换的正确方法是什么?

c++ templates

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

标签 统计

c++ ×1

templates ×1