0

Compiler complains about multiple definitions of func().

It seems have something to do with the code below residing in the header file, which is included by multiple other .cpp files. If func() is set to be inline, compilor would be happy. However, func() is expected to be executed only once... What are my options then?

namespace S
{
    const LDS &func()
    {
        static LDS ret;
        ...
        return ret;
    }
}

inline LDS &operator<<(LDS &str_,stringType1 &data_)
{
    str_ << S::func();
}

inline LDS &operator<<(LDS &str_,stringType2 &data_)
{
    str_ << S::func();
}
Sarah
  • 453
  • 7
  • 16
  • 1
    You already answered your own question. Your function needs to be inline, no matter how many times it is executed. – SergeyA Jun 15 '16 at 16:18
  • It doesn't matter how many times it's *executed*. It matters in how many translation units it will be defined. – Barry Jun 15 '16 at 16:19

0 Answers0