This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Member operator+() vs. friend operator+()


Hi

gcc gives me error messages for code that I think to be correct.

Thanks
Thomas


GCC version:
bash-2.02$ gcc -v
Reading specs from
//p/CYGWIN~1.1/CYGWIN~1/H-I586~1/bin/../lib/gcc-lib/i586-cygw
in32/2.95.2/specs
gcc version 2.95.2 19991024 (release)

System:
NT4 SP6 German

Command-line options and compiler error messages:
bash-2.02$ g++ foo.cpp
foo.cpp: In instantiation of `V<double>':
foo.cpp:29:   instantiated from here
foo.cpp:12: invalid use of undefined type `struct V<double>'
foo.cpp:13: forward declaration of `struct V<double>'
foo.cpp:12: confused by earlier errors, bailing out

foo.cpp:
template <typename T>
struct V;

template <typename T>
V<T> operator+(T, const V<T> &);

template <typename T>
struct V
{
    V operator+(T) const;
    
  friend V operator+<>(T, const V &);
};

template <typename T>
V<T> V<T>::operator+(const T c) const
{
  return V<T>(*this);
}

template <typename T>
V<T> operator+(T t, const V<T> &v)
{
  return v+t;
}

int main()
{
  V<double> v;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]