Hi,
I get "error LNK2005:" when I build my source code.

Below is what I did:

Main.cpp

#include Main.h
Function();

Main.h

#include "File1.h"
//#include "File2.h"

File1.cpp

#include "File1.h"
void Function()
{
	// Do something
}

File1.h

extern void Function()

File2.cpp

#include "File2.h"
void Function()
{
	// Do something
}

File2.h

extern void Function()

What I'm trying to do is I want to be able to run Function() from File1.cpp when I #include "File1.h" and comment #include "File2.h" in Main.h and run Function() from File2.cpp when I do the opposite. This is to give me the flexibility to change what my program do by just changing the file included instead of modifying my source code.
Please advice.
Thanks.

Be a part of the DaniWeb community

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