use*_*298 0 c++ struct parameter-passing
#include <iostream>
using namespace std;
float distance(tocki *A, tocki *B);
int main()
{
struct tocki{
int x, y;
};
tocki A, B, C;
cout << "x = ";
cin >> A.x;
cout << "y = ";
cin >> A.y;
cout << "x = ";
cin >> B.x;
cout << "y = ";
cin >> B.y;
cout << "x = ";
cin >> C.x;
cout << "y = ";
cin >> C.y;
cout << distance(&A, &B);
return 0;
}
//distance between (x1,y1) i (x2,y2) e d = sqrt((x2-x1)^2 - (y2-y1)^2);
float distance(tocki *A, tocki *B){
return sqrt(pow(A.y - A.x, 2) - pow(B.y - B.x, 2));
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
'tocki' was not declared in this scope
'A' was not declared in this scope
'tocki' was not declared in this scope
'B' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
在这一行:
float distance(tocki *A, tocki *B);
Run Code Online (Sandbox Code Playgroud)
那么,我到底做错了什么呢?我想传递一个struct to function并在main()程序中获取该函数的结果.
| 归档时间: |
|
| 查看次数: |
170 次 |
| 最近记录: |