0

SplinePoints と InterpolatedPoints のセットがあります。それらのユニオンは、FinalInterpolatedPoints に格納する必要があります。

これはメインファイルです:

#include <iostream>
#include <vector>
#include <conio.h>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <set>

using namespace std;

typedef struct SplinePoints {
int x;
double y;
SplinePoints(int a, double b) : x(a), y(b) {

}
friend bool operator < (SplinePoints const&A, SplinePoints const&B) {
    return A.x < B.x;
}
};

typedef struct InterpolatedPoints {
int x;
double y;
InterpolatedPoints(int a, double b) : x(a), y(b) {

}
friend bool operator < (InterpolatedPoints const&A, 
                InterpolatedPoints const&B) {
    return A.x < B.x;
}
};

typedef struct FinalInterpolatedPoints {
int x;
double y;
FinalInterpolatedPoints(int a, double b) : x(a), y(b) {

}
friend bool operator < (FinalInterpolatedPoints const&A, 
                FinalInterpolatedPoints const&B) {
    return A.x < B.x;
}
FinalInterpolatedPoints operator= (SplinePoints const&A) {
    x = A.x;
    y = A.y;
    return *this;
}
FinalInterpolatedPoints operator= (InterpolatedPoints const&A) {
    x = A.x;
    y = A.y;
    return *this;
}
};

inline bool operator < (InterpolatedPoints const&A, 
                SplinePoints const&B) {
return A.x < B.x;
}

int main (int argc, char** argv) {

set <SplinePoints> set1;
set <InterpolatedPoints> set2;
set <FinalInterpolatedPoints> BaseLine;

set1.insert(SplinePoints(1,2));
set1.insert(SplinePoints(2,5));
set1.insert(SplinePoints(3,8));
set1.insert(SplinePoints(4,1.66));

set2.insert(InterpolatedPoints(5,5.768));
set2.insert(InterpolatedPoints(6,5.560));
set2.insert(InterpolatedPoints(7,5.643));
set2.insert(InterpolatedPoints(8,5.313));

set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), inserter(BaseLine, BaseLine.begin()));

getch();
return 0;
}

私はそれを行うためにこの関数を使用しました:

set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), inserter(BaseLine, BaseLine.begin()));

ここで、set1、set2、および BaseLine は、それぞれ SplinePoints、InterpolatedPoints、および FinalInterpolatedPoints のタイプです。

プログラムをデバッグする<と、ヘッダー ファイルのソース ファイルを参照する '=' 演算子のテンプレート オーバーロード エラーが発生するalogrithm

template<class _InIt1,
class _InIt2,
class _OutIt> inline
_OutIt _Set_union(_InIt1 _First1, _InIt1 _Last1, _InIt2 _First2, _InIt2 _Last2, _OutIt _Dest)
{   // OR sets [_First1, _Last1) and [_First2, _Last2), using operator<
for (; _First1 != _Last1 && _First2 != _Last2; )
    **if (_DEBUG_LT(*_First1, *_First2))**
        {   // copy first
        ***_Dest++ = *_First1;**
        ++_First1;
        }
    **else if (*_First2 < *_First1)**
        {   // copy second
        ***_Dest++ = *_First2;**
        ++_First2;
        }
    else
        {   // advance both
        ***_Dest++ = *_First1;**
        ++_First1;
        ++_First2;
        }
_Dest = _STD copy(_First1, _Last1, _Dest);
return (_STD copy(_First2, _Last2, _Dest));
}

構造体の定義に演算子のオーバーロード関数を含めましたが、関数に関連するエラーのみを取り除くことができました<。次のようなエラーを取り除くのにまだ苦労しています=:

error C2679: binary '=' : no operator found which takes a right-hand operand of type 'const SplinePoints' (or there is no acceptable conversion)

助けてください!

4

2 に答える 2

0

あなたのコードには奇妙なことがいくつかあります。typedefクラスの前にドロップします。

/*drop: typedef*/ struct SplinePoints {

また、あなたoperator=の s は参照を返す必要があります。

FinalInterpolatedPoints& operator= (SplinePoints const&A) {
//                     ^ add this!
    x = A.x;
    y = A.y;
    return *this;
}

それ以外は、コンパイル可能な完全な例を提供していません。上記を修正しても問題が解決しない場合は、質問を作成して編集してください。

于 2013-03-26T13:38:25.827 に答える
0

試す:

FinalInterpolatedPoints operator= (const SplinePoints &A)

つまりconst、タイプ ( ) の前にキーワードを移動しSplinePointsます。

于 2013-03-26T13:32:50.220 に答える