我代码是这样的: #include <iostream> using namespace std; int result(int, int); const int k = 2; struct Point{ int x , y; }; int main() { int z(0), b(50); Point a; cout << "输入两个整数(以空格区分):"; cin >> a.x >> a.y; z = (a.x + a.y) * k; z = result(z, b); cout << "计算结果如下:" << endl; cout << "((" << a.x << " + " << a.y << " ) * " << k << ")+" << b << "=" << z << endl; return 0; } 但是报错了:
Scanning dependencies of target cpp
[ 50%] Building CXX object CMakeFiles/cpp.dir/main.cpp.o
[100%] Linking CXX executable cpp
Undefined symbols for architecture x86_64:
"result(int, int)", referenced from:
_main in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [cpp] Error 1
make[2]: *** [CMakeFiles/cpp.dir/all] Error 2
make[1]: *** [CMakeFiles/cpp.dir/rule] Error 2
make: *** [cpp] Error 2
千万里不及你
相关分类