Thread: Re: [Dev-C++] Is it possible - templates (.h and .cpp) ?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Eduard K. <edu...@ar...> - 2004-04-28 15:45:02
|
Hello Carla, Take a look in your in your Dev C++ main folder. There you can find a folder named Temp. In this folder you can find the templates for the "open an new project" option. The files for C++ you shuld take a look at are: all files with the extension *.template further consoleapp_*cpp*.txt for C it would be : also all files with *.template extension and consoleapp_c.txt you can also customize all other files in this directory (after a backup of these files). If you open these files with an text editor you should be able to customize them. hope could help Eduard Kiefel |
|
From: manish S. <msh...@qu...> - 2004-04-30 15:32:11
|
Well, I guess there is a keyword export(as given in Stroustrup's book) =
whose
purpose is exactly this(separate compilation strategy)..Though as far =
as I
know this is not supported by .NET and CodeWarrior.
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of Jorge
Mazzonelli
Sent: Friday, April 30, 2004 7:53 PM
To: dev...@li...
Subject: Re: [Dev-C++] Is it possible - templates (.h and .cpp) ?
Hi,
excuse me but I'm just a newbie in C++ (most of my developpements =
are
made in ANSI-C) but was curious about the subject and made some google
search and found this URL:=20
http://www.cplusplus.com/doc/tutorial/tut5-1.html. There, the author =
says at
the end the following:
/The macro-like functionality of templates, forces a restriction for
multi-file projects: the implementation (definition) of a template =
class or
function _must_ be in the same file as the declaration. That means we =
cannot
separate the interface in a separate header file and we must include =
both
interface and implementation in any file that uses the templates. /
/Going back to the library of functions, if we wanted to make a library =
of
function templates, instead of creating a header file (*.h*) we should
create a "template file" with both the interface and implementation of =
the
function templates (there is no convention on the extension for this =
type of
file other than there be no extension at all or to keep the .h). The
inclusion more than once of the same template file with both =
declarations
and definitions in a project doesn't generate linkage errors, since =
they are
compiled on demand and compilers that allow templates should be =
prepared to
not generate duplicate code in these cases. /
Hope this helped.
Jorge
Ricardo Amores Hern=E1ndez wrote:
> She=B4s not talking about Dev-C++ templates, but *C++ Language*=20
> Templates. ;) More specifically she asked if gcc separate compilation =
> of templates.
> By the way, i=B4m interested in knowing that too :)
>
--
*Jorge H. MAZZONELLI*
e-mail @: jma...@ia... <mailto:jma...@ia...>
|
|
From: Per W. <pw...@ia...> - 2004-04-30 16:29:01
|
export is noramlly used to inform that code or data is available in another object file. With templates, there are no code unless the compiler can se both the template implementation, and some references that uses the template. First then will the compiler instance a copy of the template functions, specifically adjusted according to what template parameters that was supplied. This makes it impossible to use templates without letting the compiler see the full declarations for the template. /Per W On Fri, 30 Apr 2004, manish Shrivastava wrote: > Well, I guess there is a keyword export(as given in Stroustrup's book) wh= ose > purpose is exactly this(separate compilation strategy)..Though as far as = I > know this is not supported by .NET and CodeWarrior. > > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf Of Jorge > Mazzonelli > Sent: Friday, April 30, 2004 7:53 PM > To: dev...@li... > Subject: Re: [Dev-C++] Is it possible - templates (.h and .cpp) ? > > Hi, > excuse me but I'm just a newbie in C++ (most of my developpements are > made in ANSI-C) but was curious about the subject and made some google > search and found this URL: > http://www.cplusplus.com/doc/tutorial/tut5-1.html. There, the author says= at > the end the following: > > /The macro-like functionality of templates, forces a restriction for > multi-file projects: the implementation (definition) of a template class = or > function _must_ be in the same file as the declaration. That means we can= not > separate the interface in a separate header file and we must include both > interface and implementation in any file that uses the templates. / > > /Going back to the library of functions, if we wanted to make a library o= f > function templates, instead of creating a header file (*.h*) we should > create a "template file" with both the interface and implementation of th= e > function templates (there is no convention on the extension for this type= of > file other than there be no extension at all or to keep the .h). The > inclusion more than once of the same template file with both declarations > and definitions in a project doesn't generate linkage errors, since they = are > compiled on demand and compilers that allow templates should be prepared = to > not generate duplicate code in these cases. / > > > > > Hope this helped. > > Jorge > > > Ricardo Amores Hern=E1ndez wrote: > > > She=B4s not talking about Dev-C++ templates, but *C++ Language* > > Templates. ;) More specifically she asked if gcc separate compilation > > of templates. > > By the way, i=B4m in |
|
From: Kevin B. <kev...@ma...> - 2004-05-01 04:28:17
|
>This makes it impossible to use templates without letting the >compiler see the full declarations for the template. Not entirely accurate. The C++ standard does, in fact, specify a facility for separate compilation of template code, using the export keyword. Unfortunately, there is almost no compiler support for this yet. In fact, to my knowledge only the EDG compiler supports it in any reasonably complete way. So, as a practical matter, it remains close to impossible for the immediate future. But, it is standard C++, and so eventually, anybody who wants to pretend to compliance will support it. Meanwhile, you can still divide your code into .h and .cpp, and merely use some conditional compilation to accomodate non-compliant compilers, something like so: // Global definition somewhere #if defined(USE_EXPORT) #define EXPORT export #else #define EXPORT #endif // mytemplate.h EXPORT template<class T> ...whatever... #if !defined(USE_EXPORT) #include mytemplate.cpp #endif In this way, you can divide your code, it'll work now, and you'll be ready for the future. Another option is to use explicit instatiation. This allows you to hide your implementation completely without all the preprocessor nonsense above, and still satisfy the linker by explicitly instatiating whatever various examples of the template your program happens to require. This can be a maintenance headache, though, since you need to keep track of what template variations are used by the rest of your program. /* mytemplate.cpp */ #include "mytemplate.h" // Implement template here. // Instatiate myclass for int and float, // which is all we use in the whole program. template myclass<int>; template myclass<float>; --- Kevin |
|
From:
<ri...@te...> - 2004-04-30 13:33:17
|
She´s not talking about Dev-C++ templates, but *C++ Language* Templates. ;)
More specifically she asked if gcc separate compilation of templates.
By the way, i´m interested in knowing that too :)
--
---------------------------------------------------
Ricardo Amores Hernández
ICQ: 19463735
MSN: zheo_ (at) hotmail (dot) es
---------------------------------------------------
|
|
From: Jorge M. <jma...@ia...> - 2004-04-30 14:23:14
|
Hi,
excuse me but I'm just a newbie in C++ (most of my developpements
are made in ANSI-C) but was curious about the subject and made some
google search and found this URL:
http://www.cplusplus.com/doc/tutorial/tut5-1.html. There, the author
says at the end the following:
/The macro-like functionality of templates, forces a restriction for
multi-file projects: the implementation (definition) of a template class
or function _must_ be in the same file as the declaration. That means we
cannot separate the interface in a separate header file and we must
include both interface and implementation in any file that uses the
templates. /
/Going back to the library of functions, if we wanted to make a library
of function templates, instead of creating a header file (*.h*) we
should create a "template file" with both the interface and
implementation of the function templates (there is no convention on the
extension for this type of file other than there be no extension at all
or to keep the .h). The inclusion more than once of the same template
file with both declarations and definitions in a project doesn't
generate linkage errors, since they are compiled on demand and compilers
that allow templates should be prepared to not generate duplicate code
in these cases. /
Hope this helped.
Jorge
Ricardo Amores Hernández wrote:
> She´s not talking about Dev-C++ templates, but *C++ Language*
> Templates. ;)
> More specifically she asked if gcc separate compilation of templates.
> By the way, i´m interested in knowing that too :)
>
--
*Jorge H. MAZZONELLI*
e-mail @: jma...@ia... <mailto:jma...@ia...>
|
|
From: Carla M. W. <ca...@lr...> - 2004-04-30 18:10:11
|
Hi, Thank you very much. This was exactly what I wanted to know. It is a pitty that it is not possible to divide the implementation in .h and .cpp files. Thanks, Carla. On Fri, 30 Apr 2004, Jorge Mazzonelli wrote: > Hi, > excuse me but I'm just a newbie in C++ (most of my developpements=20 > are made in ANSI-C) but was curious about the subject and made some=20 > google search and found this URL:=20 > http://www.cplusplus.com/doc/tutorial/tut5-1.html. There, the author=20 > says at the end the following: >=20 > /The macro-like functionality of templates, forces a restriction for=20 > multi-file projects: the implementation (definition) of a template class= =20 > or function _must_ be in the same file as the declaration. That means we= =20 > cannot separate the interface in a separate header file and we must=20 > include both interface and implementation in any file that uses the=20 > templates. / >=20 > /Going back to the library of functions, if we wanted to make a library= =20 > of function templates, instead of creating a header file (*.h*) we=20 > should create a "template file" with both the interface and=20 > implementation of the function templates (there is no convention on the= =20 > extension for this type of file other than there be no extension at all= =20 > or to keep the .h). The inclusion more than once of the same template=20 > file with both declarations and definitions in a project doesn't=20 > generate linkage errors, since they are compiled on demand and compilers= =20 > that allow templates should be prepared to not generate duplicate code=20 > in these cases. / >=20 >=20 >=20 >=20 > Hope this helped. >=20 > Jorge >=20 >=20 > Ricardo Amores Hern=E1ndez wrote: >=20 > > She=B4s not talking about Dev-C++ templates, but *C++ Language*=20 > > Templates. ;) > > More specifically she asked if gcc separate compilation of templates. > > By the way, i=B4m interested in knowing that too :) > > >=20 > --=20 > *Jorge H. MAZZONELLI* > e-mail @: jma...@ia... <mailto:jma...@ia...> >=20 |