Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的c++;函数未运行,我无法对其进行解码 嘿,我是新来的C++。我在C++中有以下功能,但它总是给我一个错误的“双重叠”函数,我不知道为什么。谁能告诉我,我做错了什么 double overlap(vector<double> &R1, vector<double> &R2) { // overlap in the x dimension double xmin = max(R1[0], R2[0]); double xmax = min(R1[2], R2[2]); if (xmin >= xmax) return 0; // overlap in the y dimension double ymin = max(R1[1], R2[1]); double ymax = min(R1[3], R2[3]); if (ymin >= ymax) return 0; double overlap_area = (xmax-xmin)*(ymax-ymin) return overlap_area; } int main() { vector<int> R1; vector<int> R2; // Coordinates of the rectangles // with the .push_back() function we are adding the rectangles to our vector to give it to the algorithm. // x: x-coordinate, y: y-coordinate, w: weidth, h: height - (w,h: distance from left/botton to right/top side of the rectangle) int x1 = 0, y1 = 0, w1 = 6, h1 = 9; R1.push_back(x1); R1.push_back(y1); R1.push_back(w1); R1.push_back(h1); int x2 = 3, y2 = 4, w2 = 3, h2 = 3; R2.push_back(x2); R2.push_back(y2); R2.push_back(w2); R2.push_back(h2); cout << "Overlap = " << overlap(R1, R2) << endl; } 双重重叠(向量&R1,向量&R2){ //在x维度上重叠 双xmin=max(R1[0],R2[0]); 双xmax=min(R1[2],R2[2]); 如果(xmin>=xmax)返回0; //y维度中的重叠 双ymin=max(R1[1],R2[1]); 双ymax=min(R1[3],R2[3]); 如果(ymin>=ymax)返回0; 双重叠面积=(xmax xmin)*(ymax ymin) 返回重叠区域; } int main(){ 载体R1; 载体R2; //矩形的坐标 //使用.push_back()函数,我们将矩形添加到向量中,以将其提供给算法。 //x:x坐标,y:y坐标,w:weidth,h:height-(w,h:从矩形的左侧/底部到右侧/顶部的距离) int x1=0,y1=0,w1=6,h1=9; R1.推回(x1); R1.推回(y1); R1.推回(w1); R1.推回(h1); int x2=3,y2=4,w2=3,h2=3; R2.推回(x2); R2.推回(y2); R2.推回(w2); R2.推回(h2); cout_C++_Function - Fatal编程技术网

我的c++;函数未运行,我无法对其进行解码 嘿,我是新来的C++。我在C++中有以下功能,但它总是给我一个错误的“双重叠”函数,我不知道为什么。谁能告诉我,我做错了什么 double overlap(vector<double> &R1, vector<double> &R2) { // overlap in the x dimension double xmin = max(R1[0], R2[0]); double xmax = min(R1[2], R2[2]); if (xmin >= xmax) return 0; // overlap in the y dimension double ymin = max(R1[1], R2[1]); double ymax = min(R1[3], R2[3]); if (ymin >= ymax) return 0; double overlap_area = (xmax-xmin)*(ymax-ymin) return overlap_area; } int main() { vector<int> R1; vector<int> R2; // Coordinates of the rectangles // with the .push_back() function we are adding the rectangles to our vector to give it to the algorithm. // x: x-coordinate, y: y-coordinate, w: weidth, h: height - (w,h: distance from left/botton to right/top side of the rectangle) int x1 = 0, y1 = 0, w1 = 6, h1 = 9; R1.push_back(x1); R1.push_back(y1); R1.push_back(w1); R1.push_back(h1); int x2 = 3, y2 = 4, w2 = 3, h2 = 3; R2.push_back(x2); R2.push_back(y2); R2.push_back(w2); R2.push_back(h2); cout << "Overlap = " << overlap(R1, R2) << endl; } 双重重叠(向量&R1,向量&R2){ //在x维度上重叠 双xmin=max(R1[0],R2[0]); 双xmax=min(R1[2],R2[2]); 如果(xmin>=xmax)返回0; //y维度中的重叠 双ymin=max(R1[1],R2[1]); 双ymax=min(R1[3],R2[3]); 如果(ymin>=ymax)返回0; 双重叠面积=(xmax xmin)*(ymax ymin) 返回重叠区域; } int main(){ 载体R1; 载体R2; //矩形的坐标 //使用.push_back()函数,我们将矩形添加到向量中,以将其提供给算法。 //x:x坐标,y:y坐标,w:weidth,h:height-(w,h:从矩形的左侧/底部到右侧/顶部的距离) int x1=0,y1=0,w1=6,h1=9; R1.推回(x1); R1.推回(y1); R1.推回(w1); R1.推回(h1); int x2=3,y2=4,w2=3,h2=3; R2.推回(x2); R2.推回(y2); R2.推回(w2); R2.推回(h2); cout

我的c++;函数未运行,我无法对其进行解码 嘿,我是新来的C++。我在C++中有以下功能,但它总是给我一个错误的“双重叠”函数,我不知道为什么。谁能告诉我,我做错了什么 double overlap(vector<double> &R1, vector<double> &R2) { // overlap in the x dimension double xmin = max(R1[0], R2[0]); double xmax = min(R1[2], R2[2]); if (xmin >= xmax) return 0; // overlap in the y dimension double ymin = max(R1[1], R2[1]); double ymax = min(R1[3], R2[3]); if (ymin >= ymax) return 0; double overlap_area = (xmax-xmin)*(ymax-ymin) return overlap_area; } int main() { vector<int> R1; vector<int> R2; // Coordinates of the rectangles // with the .push_back() function we are adding the rectangles to our vector to give it to the algorithm. // x: x-coordinate, y: y-coordinate, w: weidth, h: height - (w,h: distance from left/botton to right/top side of the rectangle) int x1 = 0, y1 = 0, w1 = 6, h1 = 9; R1.push_back(x1); R1.push_back(y1); R1.push_back(w1); R1.push_back(h1); int x2 = 3, y2 = 4, w2 = 3, h2 = 3; R2.push_back(x2); R2.push_back(y2); R2.push_back(w2); R2.push_back(h2); cout << "Overlap = " << overlap(R1, R2) << endl; } 双重重叠(向量&R1,向量&R2){ //在x维度上重叠 双xmin=max(R1[0],R2[0]); 双xmax=min(R1[2],R2[2]); 如果(xmin>=xmax)返回0; //y维度中的重叠 双ymin=max(R1[1],R2[1]); 双ymax=min(R1[3],R2[3]); 如果(ymin>=ymax)返回0; 双重叠面积=(xmax xmin)*(ymax ymin) 返回重叠区域; } int main(){ 载体R1; 载体R2; //矩形的坐标 //使用.push_back()函数,我们将矩形添加到向量中,以将其提供给算法。 //x:x坐标,y:y坐标,w:weidth,h:height-(w,h:从矩形的左侧/底部到右侧/顶部的距离) int x1=0,y1=0,w1=6,h1=9; R1.推回(x1); R1.推回(y1); R1.推回(w1); R1.推回(h1); int x2=3,y2=4,w2=3,h2=3; R2.推回(x2); R2.推回(y2); R2.推回(w2); R2.推回(h2); cout,c++,function,C++,Function,您声明(与定义一起)接收对双精度向量的两个引用 double overlap(vector<double> &R1, vector<double> &R2) { /* ... */ } 双重重叠(向量&R1,向量&R2) { /* ... */ } 用两个int向量调用 vector<int> R1; vector<int> R2; /* ... */ overlap(R1, R2) /* ... */ 向量R1; 载体R2;

您声明(与定义一起)接收对双精度向量的两个引用

double overlap(vector<double> &R1, vector<double> &R2)
{ /* ... */ }
双重重叠(向量&R1,向量&R2)
{ /* ... */ }
用两个int向量调用

vector<int> R1;
vector<int> R2;
/* ... */ overlap(R1, R2) /* ... */
向量R1;
载体R2;
/*…重叠(R1,R2)/**/

如果您仔细阅读错误消息,我打赌它会告诉您这一点。

您正在使用
vector
作为函数的参数
overlap
。但是在
main()
中,您声明了两个int类型的向量,并将它们传递给给给了您错误的函数

只需将向量声明为:

vector<double> R1;
vector<double> R2;

您的程序中有2个错误:

  • 语句
    double overlap_area=(xmax xmin)*(ymax ymin)
    应该是
    double overlap_area=(xmax xmin)*(ymax ymin);

  • 您正在传递一个
    std::vector
    ,并将其作为函数中的一个引用接受为
    std::vector
    ,错误正确地指出了这一点

    在函数“int main()”中: 43:43:错误:从'std::vector'类型的表达式初始化'std::vector&'类型的引用无效 6:8:注意:在传递“双重重叠(std::vector&,std::vector&)”的参数1时


  • 您需要将main中的
    R1
    R2
    更改为
    double
    type
    vector

    您得到的确切错误是什么?您忘记了在
    double overlap\u area=(xmax xmin)*(ymax ymin)末尾的分号。
    um为什么main中的数据类型int和函数中的double是“overlap”?@Moe你也可以发送最小-最大代码。需要做新的事情吗
    double overlap_area = (xmax-xmin)*(ymax-ymin)