0

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

I have

MyClass.h

class MyClass
{
public:
	static int UseIndex;
....
};

#include "MyClass.inl"

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?

Thanks,

Dave

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by daviddoria
0

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

0

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)

Dave

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.