Hi ,

Working on VC++ 2012.
"error LNK2005: "class std::basic_ofstream<char,struct std::char_traits<char> > Createonly_logs" (?Createonly_logs@@3V?$basic_ofstream@DU?$char_traits@D@std@@@std@@A) already defined in UtilityFunctions.obj

I have defined a text file (for writing the output) under LogFiles.h

include <fstream>

using namespace std;
ofstream Createonly_logs("E:\MyProj\MTEST\CreateFile_logs.txt");

I have created three .cpp under the project and all these cpp uses the text file to append the output
Create.cpp (main file)
* i call the functions defined in other 2 .cpp from here , so i add the header file

include "LogFiles.h"

UtilityFunctions.cpp (only common functions are defined here) but the output is directed to text file , so i use

include "LogFiles.h"

MemoryCalc.cpp (supports few functions which is called from Create.cpp),

include "LogFiles.h"

on compiling the code, i get the above error. How to fix this?


used static ofstream Createonly_logs("E:\MyProj\MTEST\CreateFile_logs.txt");
solved d prob

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.