How to get resolve with function redefinition error

Login to reply to this topic.
Mon, 2004-02-02 13:42
Joined: 2004-01-09
Forum posts: 188
I am getting sick  Angry  with this error, function Redefinition !!! .
 
 I am building a log file, So that i can keep track of my program memroy allocation and deallocation, to get rid of memory leaks.For that i have build a function template in a Namespace. What i am doing is that , i will  pass Object to this function, this object could be of any type, and getting information about that Object.
 

// MemTrack.h


#ifndef MEMTRACK_H
#define MEMTRACK_H

#include <f32file.h>

namespace MemTracker
{

   void LogInit(const char* logName = NULL)
   {
      //Doing Something with logName
   }

   template<class T>

   void MemLog( T* mVar )
   {
      // Doing something with mVar
   }

};

#endif

Now when i include this template function file in one file it is fine

// Myclass.cpp

#include "MemTrack.h"

MyClass::MyClass()
{
   MemTracker::MemLog(this);  //Working fine , no error
}


But when i include this MemTrack.h file in another file(s) it give me error given below

error LNK2005: "void __cdecl MemTracker::LogInit(char const *)" (?LogInit@MemTracker@@YAXPBD@Z) already defined in SEARCHFILECONTAINER.obj

PLease help me , and tell me how could i able to get access this function in multiple files  Huh: .


                         ..... Thanks in advance Cheezy

                                with best regards

                                                                                         chetan

----
Chetan Kulshrestha


Sat, 2006-03-04 07:15
Joined: 2004-12-23
Forum posts: 239
Re: How to get resolve with function redefinition error
Hi Chetan,
Have u resolved your problem.
If yes ,then could you tell me how..

BR

---------------
Bhatt Kavita

Sat, 2006-03-04 11:11
Joined: 2005-11-28
Forum posts: 101
Re: How to get resolve with function redefinition error
i think its #ifndef #define problem.. just add it to ur .h file
Mon, 2006-03-06 08:15
Joined: 2004-12-03
Forum posts: 276
Re: How to get resolve with function redefinition error
You should never define functions in your .h(header) file. Header file is only used for declarations.... definitions should be in .h file... Because header file will be included in many places so as ur definitions... thus result in multple definition error....

So move your function definition to your header file and your problem will be solved...

Dennis

Today is a gift by GOD, that's why it is called the present.

  • Login to reply to this topic.