www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/03/12:52:09

From: Matthew Mastracci <mmastrac AT acs DOT ucalgary DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Template difficulties... (GNU's method?)
Date: Wed, 2 Apr 1997 09:01:33 -0700
Organization: The University of Calgary
Lines: 76
Message-ID: <Pine.A41.3.96.970402084741.50894B-100000@acs2.acs.ucalgary.ca>
Reply-To: Matthew Mastracci <mmastrac AT acs DOT ucalgary DOT ca>
NNTP-Posting-Host: mmastrac AT acs2 DOT acs DOT ucalgary DOT ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

     I've been trying to compile some classes that use templates with
DJGPP and I've had no luck.  Each time I get unresolved reference errors
when the linked tries to create the executable.  

     I've read GNU's explanation about template instantiation (sp?), but
it says that one of my options with creating templates is to just pretend
that the compiler works with them properly (at the expense of
unnecessarily duplicated code, however).  

     I haven't tried the #interface/#implementation method mentioned in
the info file, but I want the code to be fairly portable, so it's not
really an option.  The code is similar to the following, which compiles
with the same errors:

-- external.h --:

#ifndef EXT
#define EXT

template<class T>
class Test {
public:
  Test(T Value);

  void Print(void);

  T Storage;
};

// Is this next line needed? (ie: so it's not 
// typedef class Test<int> TestInt;

#endif

-- external.cc --:

#include "external.h"
#include <iostream.h>

template<class T>
Test<T>::Test(T Value)
{
  Storage = Value;
}

template<class T>
void Test<T>::Print(void)
{
  cout << Storage;
}

-- main.cc --:

#include "external.h"

int main(void)
{
  // Or TestInt, if line in external.h is uncommented
  Test<int> a(24);
  a.Print();

  return 0;
}

     I can't see any real errors in this code, and I think it would
compile correctly under Visual C++.  I'm looking for a solution that
uses the compiler flags rather than one that uses other methods.  Thanks
in advance,

/\/\att /\/\astracci                  mmastrac AT acs DOT ucalgary DOT ca

GCS/GE    d- s+:+ a--- C++++ UA P+ L E-- W+ N++ o K+ w+ O M- V 
          PS++ PE++ Y+ PGP t+++ 5+++ X++ R++ tv+ b+++ DI++++ I 
          G++ e h r* z?


- Raw text -


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