Print
Category: Compiler and Linker
Hits: 2421

This error is caused if by linker if he finds more than one expression having the same signature.

GNU Compiler and MS VC++ Compiler will throw this error also if you have a method implementation in a header. Because the header will be included by other modules, this causes that the method will doublicated.

To avoid this use the key word inline in front of the method.


class TTest : public TZObject
{
  public:
    ...
    
    //Not a problem here. Compiler will handle this.
    Int getValue() const 
    { return m_iValue; }
      
    Int getInverseValue() const;  
    Int getInverseValue2() const;  
  private:
    Int m_iValue;
};

//Correct use
inline Int TTest::getInverseValue() const
{
  return -m_iValue;
}

//Causes problems for GNU and MS Compilers
Int TTest::getInverseValue2() const
{
  return -m_iValue;
}

See also blog entry: C++ Programming - Inline methods