You should remove inline
from the function definition. That makes it usable in Board.cpp
only.
Can't call non-static member function from imported class c++
-
01-10-2022 - |
Question
My problem is with the line memory.initBoard(); I've instantiated an instance of memory with a constructor, which resolves fine. once I try to call a member function using the dot-notation, I get an error:
Undefined symbols for architecture x86_64: "Board::initBoard()", referenced from: _main in ccpQWFDT.o ld: symbol(s) not found for architecture x86_64
I've tried removing the Board:: before initBoard in the .cpp file but that did not work. Anyone have any idea why I can't call this member function?
This is the main function
#include <iostream>
#include "Board.h"
using namespace std;
int main(){
Board memory(8);
memory.initBoard();
return 0;
}
This is the .h file
#ifndef BOARD_H
#define BOARD_H
#include <vector>
class Board {
private:
Board(){}
public:
int board_size;
Board(int size);
void initBoard();
};
#endif
This is the .cpp that goes with the .h file
#include "Board.h"
#include <iostream>
using namespace std;
Board::Board(int size) {
}
inline void Board::initBoard(){
}
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow