Pergunta

first of all I know that this question has been answered very often, but the answers didn't help me a lot...

That is the code which is causing the error.

#include "WayFinderClass.h"
WayFinderClass::WayFinderClass(int NavigationMapIndex) { ... };
int WayFinderClass::TotalNumberOfPoints(int point[100][100][2]) { ... };
int WayFinderClass::ConnectedWithXPoints(int point[100][100][2], int pointID) { ... };
void WayFinderClass::findWay(int start, int goal) { ... };

WayFinderClass.h :

#ifndef WAYFINDERCLASS_H_INCLUDED
#define WAYFINDERCLASS_H_INCLUDED
#include "NavigationMap.h"

class WayFinderClass {
    public:
        int finalWay[100];
        int start;
        int goal;
        int alreadyCheckedInt[100];
        void findWay(int start, int goal);
        WayFinderClass(int NavigationMapIndex);
    private:
        int pointConnectedWith[100];
        int wayProgress[100][100];
        int numberOfPoints;
        bool antsInProgress[100];
        int TotalNumberOfPoints(int point[100][100][2]);
        int ConnectedWithXPoints(int point[100][100][2], int pointID);
        NewNavigationMap NavigationMap;
};

#endif // WAYFINDER_H_INCLUDED

And that is the error I get:

C:\{...} Line 3 multiple definition of 'WayFinderClass::WayFinderClass(int)'

So what am I supposed to do? I already tried to include the .h file but it didn't help me. I also checked every other file whether the file WayFinderClass.cpp has been included a second time - but I found nothing.

Foi útil?

Solução

You should not include source files (.cpp). Include headers instead.

Your problem was probably caused by including the source file in main.cpp as you said and then compiling it separately as well. In that case, functions defined in WayFinderClass.cpp would be defined again in main due to the inclusion and you can't have more than one definition for a function.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top