试图将结构矩形传递到功能区域以通过引用调用进行计算
#include <iostream>
using namespace std;
int area(struct rectangle & r1)
{
return r1.length*r1.width;
}
struct rectangle
{
int length;
int width;
};
int main()
{
struct rectangle r={10,5};
int total=area(r);
std::cout << "Area is:" << total << std::endl;
}
您的代码顺序错误,应该看起来像这样
struct Rectangle
{
...
};
int area(Rectange& r1)
{
...
}
您必须在第一次使用Rectangle
之前定义它,而不是在以后定义。