Otóż piszę sobie bazę danych no i chciałem dodać plik nagłówkowy, w którym mam parę moich funkcji. Jednak gdy zalinkowałem ten plik w pliku CMenu.cpp linker wywalił mi błąd ogłaszając, że występują podwójne definicje. Nie mam pojęcia dlaczego bo umieściłem przecież strażnika nagłówka. Poniżej podaję treść pliku, z którym tkwi problem oraz cały projekt. Piszę w Visualu Studio.
http://www.speedyshare.com/580373258.html
Kod:
#pragma once
#include <iostream>
#include <math.h>
#include <string>
using std::string;
namespace My
{
unsigned int LenghtInt(int _X)
{
_X=abs(_X);
unsigned int num=0;
while(_X>0)
{
_X/=10;
num++;
}
return num;
}
//********************************
unsigned int LenghtFloat(float _X)
{
while(_X!=(int)_X)
{
_X*=10;
}
return LenghtInt((int)_X);
}
//*********************************
unsigned int LenghtFloatAfter(float _X)
{
unsigned int num=0;
while(_X!=(int)(_X))
{
_X*=10;
num++;
}
return num;
}
//********************************
unsigned int LenghtFloatBefore(float _X)
{
return LenghtInt((int)_X);
}
//********************************
string ToString(double _X)
{
string numstr, numstr2;
unsigned int after=LenghtFloatAfter((float)_X);
while(_X!=(int)(_X))
{
_X*=10;
}
int _Y=static_cast<int>(_X);
while(_Y)
{
numstr+=static_cast<char>(_Y%10+48);
_Y/=10;
}
if(after)
numstr.insert(after, 1, '.');
numstr2.resize(numstr.size());
for(int i=0, k=numstr.size()-1; i<numstr.size(); i++, k--)
{
numstr2[i]=numstr[k];
}
return numstr2;
}
}
http://www.speedyshare.com/580373258.html
Kod:
Error 1 error LNK2005: "unsigned int __cdecl My::LenghtInt(int)" (?LenghtInt@My@@YAIH@Z) already defined in CLine.obj CMenu.obj
Error 2 error LNK2005: "unsigned int __cdecl My::LenghtFloat(float)" (?LenghtFloat@My@@YAIM@Z) already defined in CLine.obj CMenu.obj
Error 3 error LNK2005: "unsigned int __cdecl My::LenghtFloatAfter(float)" (?LenghtFloatAfter@My@@YAIM@Z) already defined in CLine.obj CMenu.obj
Error 4 error LNK2005: "unsigned int __cdecl My::LenghtFloatBefore(float)" (?LenghtFloatBefore@My@@YAIM@Z) already defined in CLine.obj CMenu.obj
Error 5 error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl My::ToString(double)" (?ToString@My@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@N@Z) already defined in CLine.obj CMenu.obj
Error 6 fatal error LNK1169: one or more multiply defined symbols found D:C++Baza OCocsystems-teamDebugocsystems-team.exe