|
From: erwan a. <erw...@fr...> - 2003-01-12 08:51:33
|
Hi,
Does anybody know where I can find a detailed description on templates
syntax in C++ ?
Thanks.
Erwan
|
|
From: erwan a. <erw...@fr...> - 2003-01-12 10:26:08
|
well, this is my problem:
I would like to make a template class that owns a set of elements that have
the type of one of the class parameters. And it doesn't compile...
example:
#include <set>
template <class T>
class A
{
public:
A();
B();
std::set<T> _list;
};
the compiler's output tells that the type T is not defined... Well, of
course, but it will be defined when the template will be instanciated. So it
should be possible...
Does anybody know a solution to my problem?
|
|
From: Ioannis V. <no...@ho...> - 2003-01-12 11:38:43
|
-------Original Message-------=0D
=0D
From: erwan ancel=0D
Date: =CA=F5=F1=E9=E1=EA=DE, 12 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 2003 12:28=
:13 =EC=EC=0D
To: dev...@li...=0D
Subject: [Dev-C++] templates in C++ : precisions=0D
=0D
well, this is my problem:=0D
=0D
I would like to make a template class that owns a set of elements that ha=
ve=0D
the type of one of the class parameters. And it doesn't compile...=0D
example:=0D
=0D
#include <set>=0D
template <class T>=0D
class A=0D
{=0D
public:=0D
A();=0D
B();=0D
std::set<T> _list;=0D
};=0D
=0D
the compiler's output tells that the type T is not defined... Well, of=0D
course, but it will be defined when the template will be instanciated. So=
it=0D
should be possible...=0D
Does anybody know a solution to my problem?=0D
=0D
=0D
=3D=3D> If you remove that B() call, the code should compile.=0D
=0D
=0D
=0D
Ioannis Vranos=0D
=0D
* Programming pages: http://www.noicys.freeurl.com=0D
* Alternative URL: http://run.to/noicys=20
|
|
From: erwan a. <erw...@fr...> - 2003-01-12 13:49:45
|
This is only a function declaration, not a call. Anyway, somebody on the
gcc-help mailing list gave me a solution that seems to work: replace
"template <class T>" by "template <typename T>". But I don't know why ...
----- Original Message -----
From: "Ioannis Vranos" <no...@ho...>
To: <dev...@li...>
Sent: Sunday, January 12, 2003 12:38 PM
Subject: Re: [Dev-C++] templates in C++ : precisions
-------Original Message-------
From: erwan ancel
Date: =CA=F5=F1=E9=E1=EA=DE, 12 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 2003 12:28=
:13 =EC=EC
To: dev...@li...
Subject: [Dev-C++] templates in C++ : precisions
well, this is my problem:
I would like to make a template class that owns a set of elements that ha=
ve
the type of one of the class parameters. And it doesn't compile...
example:
#include <set>
template <class T>
class A
{
public:
A();
B();
std::set<T> _list;
};
the compiler's output tells that the type T is not defined... Well, of
course, but it will be defined when the template will be instanciated. So=
it
should be possible...
Does anybody know a solution to my problem?
=3D=3D> If you remove that B() call, the code should compile.
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld =3Domething 2 See!
http://www.vasoftware.com
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Ioannis V. <no...@ho...> - 2003-01-12 14:17:15
|
-------Original Message-------=0D =0D From: erwan ancel=0D Date: =CA=F5=F1=E9=E1=EA=DE, 12 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 2003 3:51:= 27 =EC=EC=0D To: dev...@li...=0D Subject: Re: [Dev-C++] templates in C++ : precisions=0D =0D This is only a function declaration, not a call.=0D =0D =3D=3D> Then you declared a function without a return type.=0D =0D Correct it to void B();=0D =0D =0D Anyway, somebody on the=0D gcc-help mailing list gave me a solution that seems to work: replace=0D "template <class T>" by "template <typename T>". But I don't know why ...= =0D =0D =0D =3D=3D> The typename has exactly the same effect. They are both equivalen= ts for the definition of template arguments.=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys=20 |
|
From: erwan a. <erw...@fr...> - 2003-01-12 15:02:55
|
>>The typename has exactly the same effect. They are both equivalents = for the definition of template arguments. With gcc, they don't. I did some testing: typename compiles, and class = doesn't. Perhaps gcc tries to compile something more when it knows the = template parameter is a class... |
|
From: Ioannis V. <no...@ho...> - 2003-01-12 16:05:17
|
This is non-sense (at least). Did you correct B() as i suggested?=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys =0D -------Original Message-------=0D =0D From: erwan ancel=0D Date: =CA=F5=F1=E9=E1=EA=DE, 12 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 2003 5:04:= 32 =EC=EC=0D To: Dev-C++ Mailing List=0D Subject: Re: [Dev-C++] templates in C++ : precisions=0D =0D >>The typename has exactly the same effect. They are both equivalents for the definition of template arguments.=0D =0D With gcc, they don't. I did some testing: typename compiles, and class do= esn t. Perhaps gcc tries to compile something more when it knows the template parameter is a class...=0D =0D =0D =0D =0D =20 |
|
From: erwan a. <erw...@fr...> - 2003-01-12 16:30:44
|
???
You're right. The change from class to typename made my code compile, =
but I continued with coding, and now, when I change my code from =
typename to class, it does compile... I do not know what makes it =
compile now...
Anyway, I will stay with the class keyword. I found it more beautiful :)
nb: there is no B(), this was just a simple sample to illustrate my =
problem... I thought ....
----- Original Message -----=20
From: Ioannis Vranos=20
To: Dev-C++ Mailing List=20
Sent: Sunday, January 12, 2003 5:05 PM
Subject: Re: [Dev-C++] templates in C++ : precisions
This is non-sense (at least). Did you correct B() as i =
suggested?
Ioannis Vranos
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL: http://run.to/noicys=20
-------Original Message-------
From: erwan ancel
Date: =CA=F5=F1=E9=E1=EA=DE, 12 =C9=E1=ED=EF=F5=DC=F1=E9=EF=F2 =
2003 5:04:32 =EC=EC
To: Dev-C++ Mailing List
Subject: Re: [Dev-C++] templates in C++ : precisions
>>The typename has exactly the same effect. They are both =
equivalents for the definition of template arguments.
With gcc, they don't. I did some testing: typename compiles, and =
class doesn't. Perhaps gcc tries to compile something more when it knows =
the template parameter is a class...
=20
=20
=20
|
|
From: Esteban V. <est...@ho...> - 2003-01-13 13:09:04
|
Hi, do you put all your template code in a header file and then include it
in yout main program ?
//file.h
template <class T>
class A{
A();
void B();
std::set<T> _list;
};
template <class T>
A<T>::A(){
...
}
template <class T>
void A<T>::B(){
...
}
// end file.h
// main.cc
#include "file.h"
int main(void)
{
A<int> a1;
a1.B();
return 0;
}
best regards, Esteban
|
|
From: Ioannis V. <no...@ho...> - 2003-01-13 13:26:50
|
Yes. Alternatively you can use the keyword export for the definition but that is not supported yet by all compilers.=0D =0D =0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys =0D =0D =0D -------Original Message-------=0D =0D From: Esteban Valverde=0D Date: 13 January 2003 15:13:12=0D To: dev-cpp=0D Subject: Re: [Dev-C++] templates in C++=0D =0D Hi, do you put all your template code in a header file and then include i= t=0D in yout main program ?=0D =0D //file.h=0D =0D template <class T>=0D class A{=0D A();=0D void B();=0D std::set<T> _list;=0D };=0D =0D template <class T>=0D A<T>::A(){=0D =2E..=0D }=0D =0D template <class T>=0D void A<T>::B(){=0D =2E..=0D }=0D =0D // end file.h=0D =0D // main.cc=0D #include "file.h"=0D =0D int main(void)=0D {=0D A<int> a1;=0D a1.B();=0D =0D return 0;=0D }=0D =0D best regards, Esteban=0D =0D =0D -------------------------------------------------------=0D This SF.NET email is sponsored by: FREE SSL Guide from Thawte=0D are you planning your Web Server Security? Click here to get a FREE=0D Thawte SSL guide and find the answers to all your SSL security issues.=0D http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en=0D _______________________________________________=0D Dev-cpp-users mailing list=0D Dev...@li...=0D TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm=0D https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20 |
|
From: erwan a. <erw...@fr...> - 2003-01-13 13:46:00
|
Well, this export directive is a very good idea, but which compiler supports it ? At least, gcc doesn't. ----- Original Message ----- From: "Ioannis Vranos" <no...@ho...> To: <dev...@li...> Sent: Monday, January 13, 2003 2:26 PM Subject: Re: [Dev-C++] templates in C++ Yes. Alternatively you can use the keyword export for the definition but that is not supported yet by all compilers. Ioannis Vranos * Programming pages: http://www.noicys.freeurl.com * Alternative URL: http://run.to/noicys -------Original Message------- From: Esteban Valverde Date: 13 January 2003 15:13:12 To: dev-cpp Subject: Re: [Dev-C++] templates in C++ Hi, do you put all your template code in a header file and then include it in yout main program ? //file.h template <class T> class A{ A(); void B(); std::set<T> _list; }; template <class T> A<T>::A(){ ... } template <class T> void A<T>::B(){ ... } // end file.h // main.cc #include "file.h" int main(void) { A<int> a1; a1.B(); return 0; } best regards, Esteban ------------------------------------------------------- This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues. http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users ------------------------------------------------------- This SF.NET email is sponsored by: FREE SSL Guide from Thawte are you planning your Web Server Security? Click here to get a FREE Thawte SSL guide and find the answers to all your SSL security issues. http://ads.sourceforge.net/cgi-bin/redirect.pl?thaw0026en _______________________________________________ Dev-cpp-users mailing list Dev...@li... TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm https://lists.sourceforge.net/lists/listinfo/dev-cpp-users |
|
From: Ioannis V. <no...@ho...> - 2003-01-13 13:59:41
|
The export keyword is part of the ANSI/ISO C++ standard. That means that sooner or later it will be supported by all C++ compilers. The standard a= lso guarantees that templates work if you place the same definition of them i= n every file you use them (One Definition Rule). That is, the same that you can do with inline functions. However that also means that if you change = a definition, you must recompile all the files having the (new) definition = in them.=0D =0D If i recall correctly the Intel C++ compiler supports it (but i am not 10= 0% sure). Perhaps the latest versions of GCC also support it. One thing is certain, that soon all compilers will be supporting export.=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys =0D =0D -------Original Message-------=0D =0D From: erwan ancel=0D Date: 13 January 2003 15:46:40=0D To: dev...@li...=0D Subject: Re: [Dev-C++] templates in C++=0D =0D Well, this export directive is a very good idea, but which compiler suppo= rts=0D it ? At least, gcc doesn't. |
|
From: Per W. <pw...@ia...> - 2003-01-13 14:15:50
|
Ahem. Look how soon Microsoft Visual C++ gets updated to be compatible with the C++ standard. Also, while the major players may strive for standard adherence, a lot of smaller compilers - for smaller operating systems, embedded development etc - will have a very tough time. For some platforms, there might never be a compiler with the latest C++ standard. /Per W On Mon, 13 Jan 2003, Ioannis Vranos wrote: > The export keyword is part of the ANSI/ISO C++ standard. That means that > sooner or later it will be supported by all C++ compilers. The standard also > guarantees that templates work if you place the same definition of them in > every file you use them (One Definition Rule). That is, the same that you > can do with inline functions. However that also means that if you change a > definition, you must recompile all the files having the (new) definition in > them. > > If i recall correctly the Intel C++ compiler supports it (but i am not 100% > sure). Perhaps the latest versions of GCC also support it. One thing is > certain, that soon all compilers will be supporting export. > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > -------Original Message------- > > From: erwan ancel > Date: 13 January 2003 15:46:40 > To: dev...@li... > Subject: Re: [Dev-C++] templates in C++ > > Well, this export directive is a very good idea, but which compiler supports > it ? At least, gcc doesn't. |
|
From: Ioannis V. <no...@ho...> - 2003-01-13 14:19:45
|
Well to be accurate, MS has decided to provide new releases of the VS ver= y often. The upcoming 14 April 2003 the Visual Studio 2003 will be released and VC++ will be even more ANSI C++ compliant.=0D =0D =0D For smaller platforms things may be a bit slower, but is there nowadays a= ny C compiler that does not support C90? Eventually all compilers will suppo= rt C++98.=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys =0D =0D -------Original Message-------=0D =0D From: Per Westermark=0D Date: 13 January 2003 16:14:39=0D To: Ioannis Vranos=0D Cc: dev...@li...=0D Subject: Re: [Dev-C++] templates in C++=0D =0D Ahem. Look how soon Microsoft Visual C++ gets updated to be compatible=0D with the C++ standard.=0D =0D Also, while the major players may strive for standard adherence, a lot of= =0D smaller compilers - for smaller operating systems, embedded development=0D etc - will have a very tough time. For some platforms, there might never=0D be a compiler with the latest C++ standard.=0D =0D /Per W |
|
From: Per W. <pw...@ia...> - 2003-01-13 14:38:53
|
A lot of compilers for the more unusual targets are developed by one or two persons. For a C compiler, processing the language is trivial. The only real work is to generate code - especially for some more excentric processors. Ever tried to generate code for a processor without real stack, and 8 hardcoded return addresses? While it's possible to use Lex and Yacc and write a working C compiler as an examination work at the university, trying to handle the current C++ standard is evilishly hard. Operator overloading, polymorphism, templates, multiple inherritance etc does take quite a lot of time to get correct. For a small company supplying the only C++ compiler for a specific target, there really isn't much incentives to spend man-months or man-years to go for the last standard, or to handle all of the fine-prints. In the end, if they don't make more money from selling the product then they have to spend maintaining it, there really isn't any reason to continue. /Per W On Mon, 13 Jan 2003, Ioannis Vranos wrote: > Well to be accurate, MS has decided to provide new releases of the VS very > often. The upcoming 14 April 2003 the Visual Studio 2003 will be released > and VC++ will be even more ANSI C++ compliant. > > > For smaller platforms things may be a bit slower, but is there nowadays any > C compiler that does not support C90? Eventually all compilers will support > C++98. > > > Ioannis Vranos > > * Programming pages: http://www.noicys.freeurl.com > * Alternative URL: http://run.to/noicys > > -------Original Message------- > > From: Per Westermark > Date: 13 January 2003 16:14:39 > To: Ioannis Vranos > Cc: dev...@li... > Subject: Re: [Dev-C++] templates in C++ > > Ahem. Look how soon Microsoft Visual C++ gets updated to be compatible > with the C++ standard. > > Also, while the major players may strive for standard adherence, a lot of > smaller compilers - for smaller operating systems, embedded development > etc - will have a very tough time. For some platforms, there might never > be a compiler with the latest C++ standard. > > /Per W |
|
From: Ioannis V. <no...@ho...> - 2003-01-13 15:22:00
|
I haven't played with embedded devices so far, but i assume that a mainstream embedded system like Pocket PC which has its own Visual Studio (and the upcoming VS will have integrated the mobile .NET so as to make a= pps for the Pocket PC) will have more than 1 companies making compilers for i= t. At least for Pocket PC you can expect C++98 compliance at satisfactory levels. For less mainstream devices, naturally it will take much time to = see 100% compliance.=0D =0D =0D Ioannis Vranos=0D =0D * Programming pages: http://www.noicys.freeurl.com=0D * Alternative URL: http://run.to/noicys =0D =0D -------Original Message-------=0D =0D From: Per Westermark=0D Date: 13 January 2003 16:37:41=0D To: Ioannis Vranos=0D Cc: Dev-C++ Mailing List=0D Subject: Re: [Dev-C++] templates in C++=0D =0D A lot of compilers for the more unusual targets are developed by one or=0D two persons. For a C compiler, processing the language is trivial. The=0D only real work is to generate code - especially for some more excentric=0D processors. Ever tried to generate code for a processor without real=0D stack, and 8 hardcoded return addresses?=0D =0D While it's possible to use Lex and Yacc and write a working C compiler as= =0D an examination work at the university, trying to handle the current C++=0D standard is evilishly hard. Operator overloading, polymorphism, templates= ,=0D multiple inherritance etc does take quite a lot of time to get correct.=0D For a small company supplying the only C++ compiler for a specific target= ,=0D there really isn't much incentives to spend man-months or man-years to go= =0D for the last standard, or to handle all of the fine-prints. In the end, i= f=0D they don't make more money from selling the product then they have to=0D spend maintaining it, there really isn't any reason to continue.=0D =0D /Per W=0D =0D =0D On Mon, 13 Jan 2003, Ioannis Vranos wrote:=0D =0D > Well to be accurate, MS has decided to provide new releases of the VS v= ery=0D > often. The upcoming 14 April 2003 the Visual Studio 2003 will be releas= ed=0D > and VC++ will be even more ANSI C++ compliant.=0D >=0D >=0D > For smaller platforms things may be a bit slower, but is there nowadays any=0D > C compiler that does not support C90? Eventually all compilers will support=0D > C++98.=0D >=0D >=0D > Ioannis Vranos=0D >=0D > * Programming pages: http://www.noicys.freeurl.com=0D > * Alternative URL: http://run.to/noicys=0D >=0D > -------Original Message-------=0D >=0D > From: Per Westermark=0D > Date: 13 January 2003 16:14:39=0D > To: Ioannis Vranos=0D > Cc: dev...@li...=0D > Subject: Re: [Dev-C++] templates in C++=0D >=0D > Ahem. Look how soon Microsoft Visual C++ gets updated to be compatible=0D > with the C++ standard.=0D >=0D > Also, while the major players may strive for standard adherence, a lot = of=0D > smaller compilers - for smaller operating systems, embedded development= =0D > etc - will have a very tough time. For some platforms, there might neve= r=0D > be a compiler with the latest C++ standard.=0D >=0D > /Per W =0D =20 |