* Belebele:
Quote:
In a cpp file, say a.cpp I have the following code:
>
#include <element.h>
>
struct Functor
{
void operator (Element const& ) const { /* ... */ }
};
|
No, you don't have that code.
Have you tried compiling?
Please don't type in arbitrary pseudo-code when posting: copy and paste
real code (do you understand why?).
Quote:
/* ... */
collOfElements.forEachElement(Functor());
>
Then, on another cpp file, b.cpp I have
>
#include <element.h>
>
struct Functor
{
void operator (Element const& ) const { /* different
from the functor in a.cpp */ }
};
>
/* ... */
anotherCollOfElements.forEachElement(Functor());
>
>
The code that the linker produces calls Functor::operator() defined in
a.cpp when the anotherCollOfElements (defined in b.cpp) is iterated
over.
|
You have violated the One Definition Rule (the ODR): you can't have two
classes with the same name in the same namespace, here the global one.
Put the classes in different namespaces.
E.g. anonymous namespaces.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?