How can I inline functions in header files?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//Point.h
#ifndef POINT_H
#define POINT_H

struct Point
{
   int x;
   int y;
}

bool operator==(const Point& lhs, const Point& rhs)
{
   return lhs.x == rhs.x && lhs.y == rhs.y;
}
#endif // POINT_H 


How might I use this in several translation units without the use of a corresponding .cpp file? In its current state, this would produce a "multiple definitions" error.

Is this possible? Thanks in advance!
Last edited on
1
2
3
4
inline bool operator==(const Point& lhs, const Point& rhs)
{
   return lhs.x == rhs.x && lhs.y == rhs.y;
}
Oh boy...now I feel dumb. I appreciate the help though. I was under the assumption that inline's only purpose was to act as a hint for the compiler.
Last edited on
Topic archived. No new replies allowed.