This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[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>.
- From: "jason dot hoos at syclo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jun 2008 16:32:13 -0000
- Subject: [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>.
- References: <bug-31816-14499@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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