www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/24/08:39:50

Newsgroups: comp.os.msdos.djgpp
Date: Mon, 24 Jun 1996 14:25:35 +0200 (MET DST)
From: Mark Habersack <grendel AT ananke DOT amu DOT edu DOT pl>
cc: djgpp AT delorie DOT com
Subject: Templates
Message-ID: <Pine.NEB.3.93.960624140605.5904B-100000@ananke.amu.edu.pl>
MIME-Version: 1.0

Hello,
  I haven't had the opportunity to work with C++ templates before - of course
I know what they are, I read about them and, in theory, I know how they work. 
  Recently I had to port some Borland C++ library that uses templates. After
reading the DJGPP docs it seemed that there should be no problems using it.
But... when I compiled the library (no errors here, everything was as smooth
as Michael Jackson) there appeared a problem: linker complained about
undefined symbols. There were three default constructors (defined in the
template header file) that were unseen. After examining the library source
code I have found that there were three definitions of global objects using
this template, e.g.:
  in header file:
  
    typedef MyTemplate<_a_class, _num_> MyTemplated_a_class;
    typedef MyTemplate<_b_class, _num_> MyTemplated_b_class;
    typedef MyTemplate(_c_class, _num_> MyTemplated_c_class;

where MyTemplate has a MyTemplate(void) constructor defined in header file

  and then in source:
    MyTemplated_a_class    A;
    MyTemplated_b_class    B;
    MyTemplated_c_class    C;

It may seem, that the compiler should generate calls to the (void) constructor
and everything should work fine. But not so. After examining the assembler
output I found that compiler HAVE generated the calls but HAVEN'T generated
the constructors themselves (i.e. they were eliminated from the code as being
not used). The other methods of MyTemplate (also defined inline in the header)
were present as it was to be expected. After trying all three solutions to the
templates problem proposed in GCC.INF - without success - I just changed the
global initializations to the following:

    MyTemplated_a_class  A = MyTemplate_a_class();
    etc.

As I mentioned above, I have no experience with C++ templates and maybe do not
understand them in detail and I am missing something important, but it seems
to me that the solution I have found is not very elegant - is it a bug, or is
it just the way templates work (in DJGPP at least)? 

  Mark

 /*******************************/
/** So here I am once more... **************************************/
/** When you grown up and leave your playground, where you kissed **/
/** your Prince and found your Frog - remember the Jester that    **/
/** showed you tears, a Script for Tears... ************************/
/*********************************************/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019