1

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(){

}
1
  • Are you compiling and linking both cpp files? Commented Jan 22, 2014 at 21:56

1 Answer 1

1

You should remove inline from the function definition. That makes it usable in Board.cpp only.

Sign up to request clarification or add additional context in comments.

1 Comment

or move the function to .h file if really want inline

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.