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]
Other format: [Raw text]

[Bug c++/31816] If a function foo is defined before declaring a template class A<T>, overloaded version of foo defined after the class declaration will not be available within class A<T>.



------- Comment #4 from jason dot hoos at syclo dot com  2008-06-30 16:32 -------
(In reply to comment #1)
> Fix:
> 
> Do not overload a function before and after a template class
> using it.
> 

Another workaround (if rearranging the definitions isn't feasible): before any
of the function definitions, define a template function that calls the
function, and then use that template in other template definitions:

template <class X>
void tmplQHash(X x) { qHash(x); }

void qHash(double) {}

template <class T>
struct QSet
{
  void foo()
  {
    tmplQHash(T());
  }
};

void qHash(int*) {}

int main()
{
  QSet<double> s;
  s.foo(); // ok

  QSet<int*> sp;
  sp.foo(); // ok now
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31816


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