public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* FW: Re: gcc and template
@ 2003-11-22 18:25 codaditasso
  2003-11-24 10:09 ` Claudio Bley
  0 siblings, 1 reply; 3+ messages in thread
From: codaditasso @ 2003-11-22 18:25 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2821 bytes --]


Excuse for my inaccurasy in the previous E-mail. Anyway i have obtained
from compiler the following log:

--------------------Configuration: prova2 - Debug--------------------
Compiling...
prova8.cpp
D:\Documenti\prova2\prova8.cpp: In function `void my_fun2() [with T = float]':
D:\Documenti\prova2\prova8.cpp:9:   instantiated from `void my_fun1() [with
T = float]'
D:\Documenti\prova2\prova8.cpp:19:   instantiated from here
D:\Documenti\prova2\prova8.cpp:14: warning: unused variable `float prova'

prova8.o - 2 error(s), 1 warning(s)

greetings from pinzi

> Thank you for your reply.
> I have modify the program in the following way:
>
> #include
> using namespace std;
>
> template void my_fun2();
>
> template void
> my_fun1(){
> my_fun2();
> };
>
> template void
> my_fun2(){
> T prova=1234;
> };
>
> int main()
> {
> my_fun1();
> return 0;
> };
>
> But now the compiler tell me that there is an error in my_fun2.
> Please help me.
>
>

the code above should be correct (and compiles with g++).
(BTW: Please don't say "there is an error ...", but give **details**!!
Just copy the error message.
And perhaps better send your mail (also) to the list so that other people
can participate and/or learn from it.)

Oliver

>
>
>
> >-- Messaggio Originale --
> >Date: Sat, 22 Nov 2003 13:44:42 +0000
> >From: Oliver Kullmann
> >To: codaditasso@tiscali.it
> >Subject: Re: gcc and template
> >
> >
> >>
> > Hello
> > I've tried to compile the following program with gcc:
> >
> > 1 template void
> > 2 my_fun1(){
> > 3 my_fun2();
> > 4 };
> > 5
> > 6 template void
> > 7 my_fun2(){
> > 8 T prova=1234;
> > 9 };
> > 10
> > 11 int ma
> >n()
> > 12 {
> > 13 my_fun1();
> > 14
> > 15 return 0;
> > 16 }
> >
> > but the compiler tell me that there is syntax error before > in line
3.
> > Anyway with the c++ builder the program was compiled correctly. What's
> the
> > problem? Also with t
> >e mingw I've obtained the same compile error?
> > In the gcc are not possible to call a template function with in another?
> >
> >
> > Greetings from pinzi
> >
>
> Hi,
>
> at line 3 you are using a non-dependent name ("my_fun2"), and non-dependent
> names
> >n template definitions are looked up immediately (while dependent
> names are looked up at the point of instantiation).
>
> So you need to declare my_fun2 before the definition of the function template
> my_fun1:
>
> template
> void my_fun2();
>
>
> > 1 template void
> > 2 my_fun1(){
> > 3 my_fun2();
>
> ...
>
> Oliver
>
> Oliver


__________________________________________________________________
Tiscali ADSL SENZA CANONE, paghi solo quando navighi!
E in più il modem e' GRATIS! Abbonati subito.
http://point.tiscali.it/adsl/index.shtml




[-- Attachment #2: Type: message/rfc822, Size: 4084 bytes --]

From: Oliver Kullmann <O.Kullmann@Swansea.ac.uk>
To: gcc-help@gcc.gnu.org
Subject: Re: gcc and template
Date: Sat, 22 Nov 2003 17:21:27 +0000
Message-ID: <20031122172127.GC8917@swan.ac.uk>

> Thank you for your reply.
> I have modify the program in the following way:
> 
> #include <vector>
> using namespace std;
> 
> template <class T>void my_fun2();
> 
> template <class T> void	
> my_fun1(){
> my_fun2<T>();
> };
> 
> template <class T> void
> my_fun2(){
> T prova=1234;
> };
> 
> int main()
> {
>   my_fun1<float>();
>   return 0;
> };
> 
> But now the compiler tell me that there is an error in my_fun2.
> Please help me.
> 
>

the code above should be correct (and compiles with g++).
(BTW: Please don't say "there is an error ...", but give **details**!!
Just copy the error message.
And perhaps better send your mail (also) to the list so that other people
can participate and/or learn from it.)

Oliver
 
> 
> 
> 
> >-- Messaggio Originale --
> >Date: Sat, 22 Nov 2003 13:44:42 +0000
> >From: Oliver Kullmann <O.Kullmann@Swansea.ac.uk>
> >To: codaditasso@tiscali.it
> >Subject: Re: gcc and template
> >
> >
> >> 
> > Hello 
> > I've tried to compile the following program with gcc: 
> > 
> > 1 template <class T> void 
> > 2 my_fun1(){ 
> > 3 my_fun2<T>(); 
> > 4 }; 
> > 5 
> > 6 template <class T> void 
> > 7 my_fun2(){ 
> > 8 T prova=1234; 
> > 9 }; 
> > 10 
> > 11 int ma
> >n() 
> > 12 { 
> > 13 my_fun1<float>(); 
> > 14 
> > 15 return 0; 
> > 16 } 
> > 
> > but the compiler tell me that there is syntax error before > in line 3.
> > Anyway with the c++ builder the program was compiled correctly. What's
> the
> > problem? Also with t
> >e mingw I've obtained the same compile error? 
> > In the gcc are not possible to call a template function with in another?
> > 
> > 
> > Greetings from pinzi 
> >
> 
> Hi,
> 
> at line 3 you are using a non-dependent name ("my_fun2"), and non-dependent
> names 
> >n template definitions are looked up immediately (while dependent
> names are looked up at the point of instantiation).
> 
> So you need to declare my_fun2 before the definition of the function template
> my_fun1:
> 
> template <class T>
> void my_fun2();
> 
> 
> > 1 template <class T> void
> > 2 my_fun1(){
> > 3 my_fun2<T>();
> 
> ...
> 
> Oliver
>  
> Oliver
>  
> 
> 
> 
> 
> __________________________________________________________________
> Tiscali ADSL SENZA CANONE, paghi solo quando navighi!
> E in più il modem e' GRATIS! Abbonati subito.
> http://point.tiscali.it/adsl/index.shtml
> 
> 
> 
> 




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: FW: Re: gcc and template
  2003-11-22 18:25 FW: Re: gcc and template codaditasso
@ 2003-11-24 10:09 ` Claudio Bley
  2003-11-24 19:35   ` codaditasso
  0 siblings, 1 reply; 3+ messages in thread
From: Claudio Bley @ 2003-11-24 10:09 UTC (permalink / raw)
  To: codaditasso; +Cc: gcc-help

On Sat, Nov 22, 2003 at 07:25:24PM +0100, codaditasso@tiscali.it wrote:
> 
> Excuse for my inaccurasy in the previous E-mail. Anyway i have obtained
> from compiler the following log:
> 
> --------------------Configuration: prova2 - Debug--------------------
> Compiling...
> prova8.cpp
> D:\Documenti\prova2\prova8.cpp: In function `void my_fun2() [with T = float]':
> D:\Documenti\prova2\prova8.cpp:9:   instantiated from `void my_fun1() [with
> T = float]'
> D:\Documenti\prova2\prova8.cpp:19:   instantiated from here
> D:\Documenti\prova2\prova8.cpp:14: warning: unused variable `float prova'
> 
> prova8.o - 2 error(s), 1 warning(s)

What kind of build tool are you using? There's only a warning GCC graciously
issued, nothing more. How come there are a total of 2 errors for prova8.o
reported? Seems your build tool counts lines with line numbers and without 
a "warning:" substring as an error??

-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux user                         - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: FW: Re: gcc and template
  2003-11-24 10:09 ` Claudio Bley
@ 2003-11-24 19:35   ` codaditasso
  0 siblings, 0 replies; 3+ messages in thread
From: codaditasso @ 2003-11-24 19:35 UTC (permalink / raw)
  To: Claudio Bley; +Cc: gcc-help

I have used the mingw compiler under windows. Anyway with the g++ under
linux i have no problem.


>-- Messaggio Originale --
>Date: Mon, 24 Nov 2003 11:05:42 +0100
>From: Claudio Bley <bley@cs.uni-magdeburg.de>
>To: codaditasso@tiscali.it
>Cc: gcc-help@gcc.gnu.org
>Subject: Re: FW: Re: gcc and template
>
>
>On Sat, Nov 22, 2003 at 07:25:24PM +0100, codaditasso@tiscali.it wrote:
>
> Excuse for my inaccurasy in the previous E-mail. Anyway i have obtained
> from compiler the following log:
>
> --------------------Configuration: prova2 - Debug---------
>----------
> Compiling...
> prova8.cpp
> D:\Documenti\prova2\prova8.cpp: In function `void my_fun2() [with T =
float]':
> D:\Documenti\prova2\prova8.cpp:9:   instantiated from `void my_fun1()
[with
> T = float]'
> D:\Documenti\prova2\prova8.cpp:1
>:   instantiated from here
> D:\Documenti\prova2\prova8.cpp:14: warning: unused variable `float prova'
>
> prova8.o - 2 error(s), 1 warning(s)

What kind of build tool are you using? There's only a warning GCC graciously
issued, nothing more. Ho
> come there are a total of 2 errors for prova8.o
reported? Seems your build tool counts lines with line numbers and without

a "warning:" substring as an error??

--
Claudio Bley                                 ASCII ribbon campaign (")
Debian G
>U/Linux user                         - against HTML email  X
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \



__________________________________________________________________
Tiscali ADSL SENZA CANONE, paghi solo quando navighi!
E in più il modem e' GRATIS! Abbonati subito.
http://point.tiscali.it/adsl/index.shtml



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-11-24 19:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-22 18:25 FW: Re: gcc and template codaditasso
2003-11-24 10:09 ` Claudio Bley
2003-11-24 19:35   ` codaditasso

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).