Header/Source Pecularity

Hey all,

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...
Does it use templates?
No. This particular method does use a pointer-to-member, but an alternative implementation without a pointer-to-member still has the same problem.
Well, let's look at the declarations and definition.
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

Thank you!
Last edited on
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.

Check out: http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.7
Last edited on
Ahh, wonderful. Problem solved. Thank you very much!
Topic archived. No new replies allowed.