I am trying to compile some old code a colleague gave me.

I have


class MyClass
	static int UseIndex;

#include "MyClass.inl"


int TreeNodeData::UseIndex=1;

I am getting:

multiple definition of `MyClass::UseIndex'
first defined here

I got several of these errors from function that were in the .inl file but not actually marked as "inline". I wrote "inline" in front of the functions and then the errors went away. It won't let me do the same with a variable definition. Anyone know what else I could try?



My guess is that you are including MyClass.ini on two or more *.cpp files. objects can not be declared in header files because it causes the multiple declaration link errors that you have.

Suggest you do not use MyClass.ini at all. Instead, put the initialization in one, and only one, *.cpp, such as MyClass.cpp

Ah great idea - who knows why they used this structure- but I created a .cpp file and moved the initialization there and it worked like a charm.

Thanks (as always)


This article has been dead for over six months. Start a new discussion instead.