So I've got a header/source pairing, with the usual guard words, properly arranged curly brackets, etc. But one of my method definitions only works if I place it in the HEADER file! The scope is properly defined, return type matches up, everything about it is alright. But if I put it in the source file, I get a compile-time error of "undefined reference to methodFoo". None of the other methods have this problem. What could be going on here? Thanks in advance for any help, I fear that this might be the precursor to some very bad problems if I keep developing this project...
Sure thing. I'm putting the full source up on the web; what follows is sans comments and unimportant declarations/definitions:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#ifndef INPUTMANAGER_H
#define INPUTMANAGER_H
namespace AsciiOp
{
class InputManager
{
public:
InputManager(control_scheme);
~InputManager();
//this is the problem child. TCOD_key_t is input data from the library I use.
inline TCOD_key_t getKeyData();
private:
TCOD_key_t (InputManager::*mControlFunction)(void);
//private attributes/methods
};
}
The definition in the source file is:
1 2 3 4 5 6 7 8 9 10 11 12
#include "AsciiOpInputManager.hpp"
namespace AsciiOp
{
inline TCOD_key_t InputManager::getKeyData()
{
return (this->*mControlFunction)();
}
//More defs down here. No problems with any of those.
}
Original header: people.brandeis.edu/~tai/AsciiOpInputManager.hpp
Original source: people.brandeis.edu/~tai/AsciiOpInputManager.cpp
I believe you should not have the "inline" keyword in the method prototype in your header file, it should only be in the implementation. Also the method must be defined in the header file if it is inline.