我正在尝试用C ++学习面向对象的编程,但是我在编译以下简化示例时遇到了麻烦:
TestBank.cpp:
#include <iostream>
#include "Bank.h"
int main()
{
Bank deBank;
}
Bank.h:
#ifndef BANK
#define BANK
class Bank
{
public:
Bank();
};
#endif
Bank.cpp:
#include "Bank.h"
Bank::Bank() {
//
}
当我尝试执行make TestBank
时,我收到以下错误:
c++ TestBank.cpp -o TestBank
Undefined symbols for architecture x86_64:
"Bank::Bank()", referenced from:
_main in TestBank-480209.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [TestBank] Error 1
导致此行为的原因是什么?似乎永远不会包含Bank.cpp
。我该如何解决这个问题?