我是C ++的新手,请键入以下代码来练习指针和取消引用运算符。但是,当我打印出来时,它给出了一条错误消息。我检查了错误消息,它们是来自链接器的。有人可以解释我做错了什么吗?
我正在使用Microsoft Visual Studio 2019社区。 p>
using namespace std;
/*
Errors:
LNK1120
LNK2019
*/
int main() {
int num1;
int *pNum;
int pointed;
num1 = 3;
pNum = &pointed;
pointed = 5;
passByValue(num1);
std::cout << "In main, num1 is " << num1 << endl;
return 0;
}
using namespace std;
void passByValue(int num)
{
cout << "You are using passByValue()." << endl;
cout << "num used to be " << num << "." << endl;
num = num*num;
cout << "num is now " << num << "." << endl;
}
我收到此错误:
Errors: LNK1120: 1 unresolved externals
LNK2019: unresolved external symbol "void__cdeclpassByValue(int)"?
passByValue@@YAXH@Z referenced in function_main