B
Belebele
In a cpp file, say a.cpp I have the following code:
#include <element.h>
struct Functor
{
void operator (Element const& ) const { /* ... */ }
};
/* ... */
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:perator() defined in
a.cpp when the anotherCollOfElements (defined in b.cpp) is iterated
over. My intention is that the Functor structs, although they have the
same name, are different since they reside in different files and each
functor is called when the code in its cpp file invokes it.
Moreover, if I define b.cpp's Functor:perator() outside of the class,
the intended calls are made.
I am confused as to what the linker is doing. Any idea?
Thanks
#include <element.h>
struct Functor
{
void operator (Element const& ) const { /* ... */ }
};
/* ... */
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:perator() defined in
a.cpp when the anotherCollOfElements (defined in b.cpp) is iterated
over. My intention is that the Functor structs, although they have the
same name, are different since they reside in different files and each
functor is called when the code in its cpp file invokes it.
Moreover, if I define b.cpp's Functor:perator() outside of the class,
the intended calls are made.
I am confused as to what the linker is doing. Any idea?
Thanks