473,796 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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/
DataStructureAn dEncodingDefini tion/gdcmItem.h:149: error: expected
primary-expression before '>' token

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

Oct 27 '07 #1
6 1533
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/
DataStructureAn dEncodingDefini tion/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<TSwa p>(is);
Oct 27 '07 #2
On 27 oct, 23:02, Gianni Mariani <gi4nos...@mari an.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<TSwa p>(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 objektorientier ter Datenverarbeitu ng
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
6578
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? Here's what I'm generally trying to achieve: I'm building (trying to anyway) a serialization library. Here's my design:
1
3267
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 structures (ints), and more complex data structures (strings and vectors) in it, and would like to write the entire class to a data file that could then be read back and loaded. However I'm having difficulty with this -- I found out (due to an...
4
1869
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
2
2114
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, ID and VALUE. I would like to create a templated column in the datagrid that is bound to the VALUE column of the datasource.
6
1316
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 columns work find as long as I pass in a dataset but if I pass in a collection of objects then they won't work unless I can cast the correct object and then fill in the column with the object. My current code looks like this: public void...
2
1690
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 like this... I have a few classes all templated by one type. Inside one of the classes is a templated member function. When I try to use this templated function in another class, the compiler complains with: error: expected primary-expression...
8
1509
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 necessary. My problem is how to construct dummy data consistent with the type the class was instantiated with. My class, stripped to it's essentials for my purpose here, is: template <class T> class Stack {
2
2939
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
2290
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 <stack> template <class T> class A { public:
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10217
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.