首页 > 解决方案 > 模板之外的复制赋值运算符

问题描述

我有一堂课

class A : public B
{
public:
    // 1st copy assignment with parameter pack
    template<class Arg>
    A& operator=(Arg&& arg)
    {
        B::operator=(std::forward<Args>(arg));
        return *this;
    }

    // 2nd copy assignment with const A&
    A& operator=(const A& arg)
    {
        // some code
    }
};

第二个不要求以下

A a, b;
a = b;

如何让编译器为上述代码调用第二个?

标签: c++templatesc++17copy-assignment

解决方案


推荐阅读