"<class-name> already defined here"

I've got quite a large project I'm working on and lets say I've made an additional maths library for certain special functions which make my life easier...
Multiple areas of the project need to use this library but because of this I get LOADS of the same error mentioning that the code is already defined in <(pretty much everywhere)>.obj.

No matter whether I use #pragma once or use manual include protection, I still get the file being defined repeatedly, how do I prevent this?
Last edited on
I suppose that your header have function definitions. If so, you should leave only declarations here and move definitions in another cpp file

Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//header.h
#ifndef HEADER_H
#define HEADER_H
void myFunc(int x, int y);
int returnInt(double f);
#endif

//header.cpp
#include "header.h"
void myFunc(int x, int y)
{
    x  + y;
}

int returnInt(double f)
{
    return f;
}

//any other file
#include "header.h" //No multiple definitions here 
And you just should add header.cpp to your compile list
Last edited on
Now I feel dumb...
Perhaps I need a day off XD

But cheers!
Topic archived. No new replies allowed.