473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Handling templated code

Hi there,

I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)

The problem is that I often struggle : when to include those txx
files ? As a rule of thumb I try to include them only once in some
central .cxx file. I have been searching the C++ FAQ for such rules of
thumbs. Are any good practices to follow, I have been browsing through
the STL of gcc and they manage to implement everything in the
interface file.

I can reproduce the issue with gcc 3.x / gcc 4.x and visual studio
2005 and they all give different errors...but on the same line :)

Thanks,
-Mathieu

For reference here is the gcc 3.x error:

/home/mmalaterre/Projects/gdcm/trunk/Source/
DataStructureAndEncodingDefinition/gdcmItem.h:149: error: expected
primary-expression before '>' token

http://gdcm.svn.sourceforge.net/view...ion/gdcmItem.h

Oct 27 '07 #1
6 1513
mathieu wrote:
Hi there,

I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)

The problem is that I often struggle : when to include those txx
files ?
Kind of pointless. I place all the template code in the .h file. If
the compiler supports the "export" command then it may work but since
only one commercial (Comeau) compiler does so, you're outa luck.
>... As a rule of thumb I try to include them only once in some
central .cxx file. I have been searching the C++ FAQ for such rules of
thumbs. Are any good practices to follow, I have been browsing through
the STL of gcc and they manage to implement everything in the
interface file.

I can reproduce the issue with gcc 3.x / gcc 4.x and visual studio
2005 and they all give different errors...but on the same line :)

Thanks,
-Mathieu

For reference here is the gcc 3.x error:

/home/mmalaterre/Projects/gdcm/trunk/Source/
DataStructureAndEncodingDefinition/gdcmItem.h:149: error: expected
primary-expression before '>' token

http://gdcm.svn.sourceforge.net/view...ion/gdcmItem.h
Just a guess but try replacing 194 with this:

nested.template ReadNested<TSwap>(is);
Oct 27 '07 #2
On 27 oct, 23:02, Gianni Mariani <gi4nos...@marian.wswrote:
mathieu wrote:
Hi there,
I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)
The problem is that I often struggle : when to include those txx
files ?

Kind of pointless. I place all the template code in the .h file. If
the compiler supports the "export" command then it may work but since
only one commercial (Comeau) compiler does so, you're outa luck.
....two. AFAIK intel icc supports the export keyword (at least on
*NIX).

ref:
http://www.intel.com/support/perform.../cs-015003.htm

....
The export keyword for templates is supported in Intel® C++ Compiler
for Linux* 8.1 or newer. It is supported in the Intel® C++ Compiler
for Mac OS*. But it is not supported in the Intel® C++ Compiler for
Windows*.
....
>
Just a guess but try replacing 194 with this:

nested.template ReadNested<TSwap>(is);
Hum... did the trick. I guess my class is templated and the function
is too... I don't remember I had to do it this way.

Thanks a bunch you saved me a lot of troubles,
-Mathieu

Oct 27 '07 #3
On 2007-10-27 21:40, mathieu wrote:
Hi there,

I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)

The problem is that I often struggle : when to include those txx
files ?
I usually just put it all in the .h file, but I recently I tried a
similar scheme with the implementation in .hpp files. But with the twist
that I included the .hpp file at the end of the .h file (which gives the
same effect as if it was all in the .h files but made the .h files a bit
"cleaner".

--
Erik Wikström
Oct 28 '07 #4
On Oct 28, 10:54 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-27 21:40, mathieu wrote:
I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)
The problem is that I often struggle : when to include those txx
files ?
I usually just put it all in the .h file, but I recently I tried a
similar scheme with the implementation in .hpp files. But with the twist
that I included the .hpp file at the end of the .h file (which gives the
same effect as if it was all in the .h files but made the .h files a bit
"cleaner".
It's also much easier to switch to export using this scheme,
when it becomes available.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 28 '07 #5
On Oct 28, 1:54 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-10-27 21:40, mathieu wrote:
Hi there,
I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)
The problem is that I often struggle : when to include those txx
files ?

I usually just put it all in the .h file, but I recently I tried a
similar scheme with the implementation in .hpp files. But with the twist
that I included the .hpp file at the end of the .h file (which gives the
same effect as if it was all in the .h files but made the .h files a bit
"cleaner".

--
Erik Wikström
I have seen the usage that Erik mentioned. It seems to have worked
till now. It is clean, and it works.

Nov 7 '07 #6
Erik Wikström wrote:
On 2007-10-27 21:40, mathieu wrote:
>Hi there,

I am currently struggling with a compiler error on a templated code.
The error is complete non-sense. I think the issue here is that I am
including files in a loop. To handle templates I usually have 3 types
of files:
- .h : interface + inline function
- .cxx : implementation (no templates)
- .txx: implementation of templates (with #if blocker to prevent
multiple inclusion)

The problem is that I often struggle : when to include those txx
files ?

I usually just put it all in the .h file, but I recently I tried a
similar scheme with the implementation in .hpp files. But with the twist
that I included the .hpp file at the end of the .h file (which gives the
same effect as if it was all in the .h files but made the .h files a bit
"cleaner".
With a conditional include, it also works with compilers that don't
require the template definitions to be included in the header.

--
Ian Collins.
Nov 7 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
1
by: Sean W. Quinn | last post by:
Hey folks, I have a question regarding file handling, and the preservation of class structure. I have a class (and I will post snippets of code later in the post) with both primitive data...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
2
by: | last post by:
Hello All, I am having a lot of difficulty trying to bind a templated column, that is programmatically created for a datagrid, to a datasource column. I have a datasource containing 2 columns,...
6
by: Alex | last post by:
I have been loving the templated datacolumns of the datagrid. I have stumbled onto a problem though that is beyond by knowledge and I was hoping someone here could jumpstart me. My templated...
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
8
by: RichardOnRails | last post by:
I have a Stack class that works fine. In particular, when it encounters an error, it cout's a msg and exits. However, I'd like to change it to report the error and continue with dummy data as...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.