* template question
@ 2002-12-04 8:00 Zoltan Nagy
2002-12-04 9:24 ` Alexander Sieb
0 siblings, 1 reply; 4+ messages in thread
From: Zoltan Nagy @ 2002-12-04 8:00 UTC (permalink / raw)
To: gcc
Hi,
I tried to compile the small code below using the g++-3.2.1 but I got
the following error message:
test.cc: In member function `void C<TTT>::ff() [with TTT = double]':
test.cc:31: instantiated from here
test.cc:20: no matching function for call to `A<double>::f(B<const
double&, double>&, double&)'
Is it a bug in the compiler or I do something wrong?
Cheers,
Zoltan
template<class T1, class T2>
struct B {
typedef T2 res_type;
};
template<class TT>
struct A {
template<class T1, class T2>
void f(const B<T1,T2>&, T1){}
};
B<const double&, double> b;
template <class TTT>
struct C {
void ff() {
double x =12;
a.f(b, x);
}
A<TTT> a;
};
int main()
{
C<double> c;
c.ff();
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: template question
2002-12-04 8:00 template question Zoltan Nagy
@ 2002-12-04 9:24 ` Alexander Sieb
0 siblings, 0 replies; 4+ messages in thread
From: Alexander Sieb @ 2002-12-04 9:24 UTC (permalink / raw)
To: gcc
Zoltan Nagy wrote:
>
> Hi,
>
> I tried to compile the small code below using the g++-3.2.1 but I got
> the following error message:
>
> test.cc: In member function `void C<TTT>::ff() [with TTT = double]':
> test.cc:31: instantiated from here
> test.cc:20: no matching function for call to `A<double>::f(B<const
> double&, double>&, double&)'
>
> Is it a bug in the compiler or I do something wrong?
>
Seems like T1 is ambiguous.
template<class T1, class T2>
void f(const B<T1,T2>&, T1){}
^^ ^^
|| ||
const double& from b. double from function call
||
\/
What should T1 really be?
In b you define what becomes T1 as const double& while in the member function call
the second parameter is double. T1 cannot be both at the same time.
--
Regards,
Alexander
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: template question.
1998-10-14 21:17 Satish
@ 1998-10-29 19:35 ` Alexandre Oliva
0 siblings, 0 replies; 4+ messages in thread
From: Alexandre Oliva @ 1998-10-29 19:35 UTC (permalink / raw)
To: Satish; +Cc: egcs
Satish <satish@dakotacom.net> writes:
> Foo<Bar *>::Foo(void) /var/tmp/cc0wXca01.o
Templates must be defined in every translation unit in which they're
used, unless you explicitly instantiate them.
> Also, the presence of def. for operator<< (comments removed)
> causes the following error, where I expected it to work just fine..
Check http://egcs.cygnus.com/faq.html#friend
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
^ permalink raw reply [flat|nested] 4+ messages in thread
* template question.
@ 1998-10-14 21:17 Satish
1998-10-29 19:35 ` Alexandre Oliva
0 siblings, 1 reply; 4+ messages in thread
From: Satish @ 1998-10-14 21:17 UTC (permalink / raw)
To: egcs
Hi,
I have just started using the egcs-1.0.3 compiler.
I ran into a problem which works fine with SGI CC
compiler. Can you please point out how to make it
work.
Here is a sample that shows the problem..
I get these errors trying to compile the basic skeleton programs
shown below:
Undefined first referenced
symbol in file
Foo<Bar *>::Foo(void) /var/tmp/cc0wXca01.o
ld: fatal: Symbol referencing errors. No output written to tmp
collect2: ld returned 1 exit status
Also, the presence of def. for operator<< (comments removed)
causes the following error, where I expected it to work just fine..
Do I need to use -fguiding-decls?
In file included from main.C:2:
templ.h:12: warning: friend declaration `class ostream & operator
<<(class ostream &, const class Foo<T> &)'
templ.h:12: warning: will not be treated as a template instantiation
templ.h:12: warning: unless you compile with -fguiding-decls
templ.h:12: warning: or add <> after the function name
The file listings are as follows:
main.C
-------
#include "templ.h"
#include "bar.h"
void main( void ){
Foo<Bar*>* foo = new Foo<Bar*>();
}
templ.C
-------
#include "templ.h"
template <class T>
Foo<T>::Foo( void ) {
}
template <class T>
void Foo<T>::bar( T& t ) const {
}
/*
template <class T>
ostream& operator<<( ostream& os, const Foo<T>& t ) {
return os;
}
*/
templ.h
-------
#ifndef TEMPL_H_
#define TEMPL_H_
#include <iostream.h>
template <class T>
class Foo {
public:
Foo( void );
void bar( T& t ) const;
//friend ostream& operator<<( ostream&, const Foo<T>& );
};
#endif
Thanks,
Satish.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-12-04 17:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-04 8:00 template question Zoltan Nagy
2002-12-04 9:24 ` Alexander Sieb
-- strict thread matches above, loose matches on Subject: below --
1998-10-14 21:17 Satish
1998-10-29 19:35 ` Alexandre Oliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).