したがって、問題は35行目(edgeListコンストラクターを呼び出します)で発生します。それはそのポイントに到達するたびに、私はエラーここオブジェクトをクラスに渡し、一致する関数エラーを受け取らない
main.cpp:35:60: error: no matching function for call to 'point::point()'
が
class edgeList {
private:
point origin;
point terminal;
double weight;
public:
edgeList(const point& origin, const point& terminal) {
this->origin = origin;
this->terminal = terminal;
this->weight = findWeight(origin, terminal);
}
int findWeight(point origin, point terminal) {
return sqrt(pow((terminal.place('x') - origin.place('x')), 2) + pow((terminal.place('y') - origin.place('y')), 2));
}
};
問題領域だと、ここで完全なコード
#include <iostream>
#include <string.h>
#include <fstream>
#include <vector>
#include <math.h>
using namespace std;
class point { //Creates the class that stores x and y coordinates
private:
double x;
double y;
public:
point(double x, double y) {
this->x = x;
this->y = y;
}
double place(char c) {
if (c == 'x') {
return this->x;
}
else if (c == 'y') {
return this->y;
}
else {
return -1;
}
}
};
class edgeList {
private:
point origin;
point terminal;
double weight;
public:
edgeList(const point& origin, const point& terminal) {
this->origin = origin;
this->terminal = terminal;
this->weight = findWeight(origin, terminal);
}
int findWeight(point origin, point terminal) {
return sqrt(pow((terminal.place('x') - origin.place('x')), 2) + pow((terminal.place('y') - origin.place('y')), 2));
}
};
int main(int argc, char *argv[]) {
double x;
double y;
int i = 0; //FIXME: DELETE THIS AFTER TESTING
vector<point> origin;
if (argv[1] == NULL) {
cout << "ERROR: NO FILE NAME FOUND" << endl;
return -1;
}
if (strcmp(argv[1], "random") != 0) {
cout << argv[1] << endl;
ifstream fp;
fp.open(argv[1]);
if (!fp.is_open()) {
cout << "ERROR: NO FILE FOUND" << endl;
return -1;
}
while (!fp.eof()) {
fp >> x;
cout << x << " ";
fp >> y;
cout << y << endl;
point pnt(x,y);
origin.push_back(pnt);
cout << "Point children" << endl << origin[i].place('x') << " " << origin[i].place('y') << endl;
i++; //FIXME: DELETE THIS AFTER TESTING
}
edgeList z(origin[0], origin[1]);
}
return 0;
}
は、私がここで間違ってやっている何を得ますか?
あなたは 'point'クラスに' point() 'コンストラクタを実装していません –
@RajeevSingh:コメントではありません –