我知道这个问题一直得到解答,但我无法为我的具体示例找到解决方案。这是完整的错误:
g++ main.cpp
Undefined symbols for architecture x86_64:
"Board::display()", referenced from:
_main in cc7hPZpy.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我只是想从我的 Board 类中提取这个显示功能。这里主要:
#include "Board.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Some Asian Game" << endl;
Board base;
base.display();
//this is creating the error
//commenting it out compiles, but obviously does not do what i want.
return 0;
}
和 Board.h:
#ifndef Board_H
#define Board_H
#include "Row.h"
#include <vector>
using namespace std;
class Board
{
public:
vector<Row> rows;
Board()
{
vector<Row> (15);
}
void play(int row, int col, char clr);
bool checkWin(int row, int col, char clr);
char getCellColor(int row, int col);
void display();
void empty();
};
#endif
以及 board.cpp 中的特定功能
void Board::display()
{
for(int i=0;i<16;i++)
{
for(int i2=0;i2<16;i2++)
{
cout << rows[i].cells[i2].getState();
}
}
}
我经常参考这个网站来寻求答案,但从未亲自使用过它,所以请耐心等待我的回复。我很肯定这很简单,但我只是忽略了。