I'm relatively inexperience when it comes to debugging linker error. I don't see how this code setup that I have would cause the linker to throw an error. Please help point out my obliviousness.
// This is the header file
class A
{
public:
//Constructor, methods, etc.
static unsigned int const length = 5;
};
class B
{
public:
// Constructor, methods, etc.
inline unsigned int const & GetLength(void)
{
return A::length;
}
};
I'm getting the linker error saying that in the source file (cpp) there's an undefined reference in the GetLength() function to 'A::length'. Does this means that I HAVE to define that function in the source file instead of the header? Why? I thought since I have the declaration of the variable in a class above, it should be able to find reference to that variable?
EDIT: Sorry if I sound ignorant, but I thought that with static variables of integral types, you can both define and declare it inside the class' definition, which is what I did. It's only with the non-integral type that you have to define it outside of the class' definition like in the duplicate post.