如何在C++ STL中实现自己的配对功能

如何在C++ STL中实现自己的配对功能,c++,class,stl,C++,Class,Stl,我试图自己创建一个pair类,但我坚持创建自己的make_pair函数。 我正在添加的实现代码,请告诉我为什么会显示错误 template<class data_type1,class data_type2> class Pair { public: //member variables data_type1 first; data_type2 second; //constructor Pair() { /

我试图自己创建一个pair类,但我坚持创建自己的make_pair函数。 我正在添加的实现代码,请告诉我为什么会显示错误

template<class data_type1,class data_type2>
class Pair
{
    public:
    //member variables
    data_type1 first;
    data_type2 second;

    //constructor

    Pair()
    {
        //default contstructor
    }

    Pair(Pair<data_type1,data_type2> &p)
    {
        first=p.first;
        second=p.second;
    }

    void operator=(Pair<data_type1,data_type2> p)
    {
        first=p.first;
        second=p.second;
        return;
    }
};

//generic function
template<class data_type1,class data_type2> 
Pair<data_type1,data_type2> makePair(data_type1 a,data_type2 b)
{
    Pair<data_type1,data_type2> temp;
    temp.first=a;
    temp.second=b;
    return temp;
}

这里,当我尝试这样对P= MaxeBe100,沙特这显示了我的错误,没有创建对:< /P>你得到什么错误消息?请具体地告诉我错误。你知道C++和对是两个不同的东西,对吧?这是一种区分大小写的语言。void运算符=对p-完全不需要。我建议您去掉整个函数。如果我更正大小写错误,假设它是问题中的一个输入错误,我会得到错误:请求从“Pair”转换为非标量类型“Pair”。这就是你的错误吗?