T
thinktwice
i have just made a test project win32 console)
//file : func.h
#ifndef _FUNC_H_
#define _FUNC_H_
void func1()
{
return;
};
void func2()
{
return;
};
#endif
//file : use1.cpp
#include "func.h"
void user1()
{
func1();
func2();
}
//file : use2.cpp
#include "func.h"
void user1()
{
func1();
func2();
}
//file : main.cpp
int main(int argc, char* argv[])
{
return 0;
};
but it failed when linking
Linking...
use2.obj : error LNK2005: "void __cdecl func1(void)" (?func1@@YAXXZ)
already defined in use1.obj
use2.obj : error LNK2005: "void __cdecl func2(void)" (?func2@@YAXXZ)
already defined in use1.obj
Debug/HelloWorld.exe : fatal error LNK1169: one or more multiply
defined symbols found
Error executing link.exe.
but it works if the function is template function. why?
//file : func.h
#ifndef _FUNC_H_
#define _FUNC_H_
void func1()
{
return;
};
void func2()
{
return;
};
#endif
//file : use1.cpp
#include "func.h"
void user1()
{
func1();
func2();
}
//file : use2.cpp
#include "func.h"
void user1()
{
func1();
func2();
}
//file : main.cpp
int main(int argc, char* argv[])
{
return 0;
};
but it failed when linking
Linking...
use2.obj : error LNK2005: "void __cdecl func1(void)" (?func1@@YAXXZ)
already defined in use1.obj
use2.obj : error LNK2005: "void __cdecl func2(void)" (?func2@@YAXXZ)
already defined in use1.obj
Debug/HelloWorld.exe : fatal error LNK1169: one or more multiply
defined symbols found
Error executing link.exe.
but it works if the function is template function. why?