1>GameWinMain.obj : error LNK2005: "bool __cdecl BPredicate(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?BPredicate@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) already defined in Algorithms.obj
1>C:\Algorithms.exe : fatal error LNK1169: one or more multiply defined symbols found
Я получаю последнее, когда пытаюсь объявить функцию в заголовке.Я не уверен, что является причиной этого, все имеет охранников.Самое смешное: если я определяю функцию в заголовке как встроенную, она компилируется.Кто-нибудь может помочь?
Смотрите код ниже:
Algorithms.h
#pragma once
//...other code
bool BPredicate(const string& a, const string& b){
string::const_iterator it;
UINT numA = 0;
UINT numB = 0;
for (it = a.begin(); it != a.end(); ++it) {
if((*it) == ' ') {
if (*(it-1) != ' ') {
++numA;
}
}
}
for (it = b.begin(); it != b.end(); ++it) {
if((*it) == ' ') {
if (*(it-1) != ' ') {
++numB;
}
}
}
return (numA < numB);
}
GameWinMain.h
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow);
GameWinMain.cpp
#include "GameWinMain.h"
#include "GameEngine.h"
#include "Algorithms.h"
#define GAME_ENGINE (GameEngine::GetSingleton())
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
if (GAME_ENGINE == NULL) return FALSE;
GAME_ENGINE->SetGame(new Algorithms());
return GAME_ENGINE->Run(hInstance, iCmdShow);
}