既然你使用的是C++,如果你愿意的话xc
and yc
要更改,您可以使用参考:
void trans(double x, double y, double theta, double& m, double& n)
{
m=cos(theta)*x+sin(theta)*y;
n=-sin(theta)*x+cos(theta)*y;
}
int main()
{
// ...
// no special decoration required for xc and yc when using references
trans(center_x, center_y, angle, xc, yc);
// ...
}
然而,如果您使用 C,则必须传递显式指针或地址,例如:
void trans(double x, double y, double theta, double* m, double* n)
{
*m=cos(theta)*x+sin(theta)*y;
*n=-sin(theta)*x+cos(theta)*y;
}
int main()
{
/* ... */
/* have to use an ampersand to explicitly pass address */
trans(center_x, center_y, angle, &xc, &yc);
/* ... */
}
我建议查看C++ FAQ Lite 的参考条目 https://isocpp.org/wiki/faq/references有关如何正确使用参考文献的更多信息。