每次我尝试编译此程序时,都会出现以下错误:
Undefined symbols for architecture x86_64:
"Character::setTime(int)", referenced from:
awesome(Character) in ccmsAc4F.o
"Character::getMoney()", referenced from:
_main in ccmsAc4F.o
"Character::setMoney(double)", referenced from:
awesome(Character) in ccmsAc4F.o
"Character::Character()", referenced from:
_main in ccmsAc4F.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
字符编译正确并且没有错误。问题似乎是试图将对象作为参考传递。以下是我的程序:
#include <cstdlib>
#include "Character.h"
#include <iostream>
using namespace std;
void awesome(Character& character);
int main() {
Character userCharacter;
awesome(userCharacter);
cout << userCharacter.getMoney();
return 0;
}
void awesome(Character& character)
{
character.setTime(0);
character.setMoney(0.00);
}
有人对我做错了什么有任何见解吗?最终在一个更大的程序中,我想使用引用来编辑一个已经实例化的对象。我假设引用是正确的方法。任何帮助将不胜感激。