1

这是我目前得到的编译器错误

错误 C2679:二进制“=”:未找到采用“对”类型的右侧操作数的运算符(或没有可接受的转换)

using namespace std;

template<typename T, typename U>
Array< Pair<T, U>>* zip(Array<T> & lhs,Array<U> & rhs) 
{
    int zipLen = (lhs.getLength() < rhs.getLength() ? lhs.getLength() : rhs.getLength());

    Array<Pair<T, U>>* zipped= new Array<Pair<T,U>>(zipLen);

    for (int i=0; i<zipLen; i++)
        zipped[i] = Pair<T, U>(lhs[i], rhs[i]);//and this is the line giving me problems

    return zipped;
}

int main()
{
    Array<int> a1(5);
    Array<char>a2(3);

    Array<Pair<int,char>>*a3;

    for(int i =1;i<5;i++)
        a1[i-1]=i;

    for(char ch='a';ch<='c';ch++)
        a2[ch-'a']=ch;

    a3=zip(a1,a2);

    cout<<a3;

    system("pause");
    return 0;
}
4

1 回答 1

2

我相信您已将“压缩”声明为指向对数组的指针。因此,要访问数组的元素,您必须首先取消引用指针:

(*zipped)[i] = Pair<T, U>(lhs[i], rhs[i]);
于 2013-04-02T17:48:46.263 回答