Timothy Madden
2010-01-29 19:56:47 UTC
Hello
I have Visual Studio 2008 Service Pack at work and I would like to write
my template code in a .cpp file, and only the template declarations in
the .h or .hpp file, as if export would be supported and as if I could
export my templates.
However without export support for such separation to actually work the
header file will include the .cpp file with a conditional compilation
directive like
#ifndef USE_EXPORT
# include "File.cpp"
#endif
and also, for things to work, the .cpp file should include only template
or inline functions definitions. Please don't bother too much with the
ugly idea that I include a .cpp file; the file is really meant to define
templates only and be included if necessary.
The advantage is that with export support I would then just define
USE_EXPORT for my project and all templates, already separated in .cpp
files, will no longer be bodily included and will get exported.
If you have read some things about templates a little you will find that
this is a quite known approach and that it works very nice.
However for that I would like to declare my templates with the export
keyword, and have the compiler ignore it (as other compilers do, to
support this separation model).
I see my cl already outputs a warning that export 'is not yet supported,
but reserved', but immediately after the warning I also get an error,
which is a problem.
Can I somehow get the compiler to ignore export with some options or
pragmas ?
I know I can use a define instead, that will expand to export only when
possible, but I would really like to keep my code clear, with the export
keyword as is, and rather set some project options to avoid my problem ...
Thank you,
Timothy Madden
I have Visual Studio 2008 Service Pack at work and I would like to write
my template code in a .cpp file, and only the template declarations in
the .h or .hpp file, as if export would be supported and as if I could
export my templates.
However without export support for such separation to actually work the
header file will include the .cpp file with a conditional compilation
directive like
#ifndef USE_EXPORT
# include "File.cpp"
#endif
and also, for things to work, the .cpp file should include only template
or inline functions definitions. Please don't bother too much with the
ugly idea that I include a .cpp file; the file is really meant to define
templates only and be included if necessary.
The advantage is that with export support I would then just define
USE_EXPORT for my project and all templates, already separated in .cpp
files, will no longer be bodily included and will get exported.
If you have read some things about templates a little you will find that
this is a quite known approach and that it works very nice.
However for that I would like to declare my templates with the export
keyword, and have the compiler ignore it (as other compilers do, to
support this separation model).
I see my cl already outputs a warning that export 'is not yet supported,
but reserved', but immediately after the warning I also get an error,
which is a problem.
Can I somehow get the compiler to ignore export with some options or
pragmas ?
I know I can use a define instead, that will expand to export only when
possible, but I would really like to keep my code clear, with the export
keyword as is, and rather set some project options to avoid my problem ...
Thank you,
Timothy Madden