calling c type function

Hi ,
I am using Visual studio 2008
I have a separate .cpp file in which i put the definition of the function .

1
2
3
4
5
6
7
8
#include "Tree.h"
//extern void func(int years);
extern void func(int years)
{
	CTree tree(18);
	tree.Growth(years);
	tree.PrintSize();
}


When i try to call this function (func) in main I am getting the error.

Treeoper.obj : error LNK2005: "void __cdecl func(int)" (?func@@YAXH@Z) already defined in Banayan.obj


Help me to understand this .
Thanks in advance .
Apparently you already have another function called func somewhere.
The extern also shouldn't be there.
Are you perhaps including the file you showed here in main.cpp?
Last edited on
Athar, I have checked everywhere in the code for the function func . but i find it no where other then the defination in this file and calling of the function in the main .
Also i have included this file in the main.
Also i have included this file in the main.

Yeah, that's the problem. Now func exists in two modules: in main.cpp and the included file.
You need to include the header file instead of the .cpp file. The header file should just contain forward declarations that tell the compiler that the function is defined in some other module.
Thanks Athar ..it worked .. thanks.
Topic archived. No new replies allowed.