home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / cplus / 1898 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  1.9 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!zaphod.mps.ohio-state.edu!cs.utexas.edu!ut-emx!jamshid
  2. From: jamshid@ut-emx.uucp (Jamshid Afshar)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: need help compiling (linking) Borland C++ programs using templates
  5. Summary: #include the .cpp file in the template's header file
  6. Message-ID: <85727@ut-emx.uucp>
  7. Date: 22 Dec 92 21:52:07 GMT
  8. References: <1992Dec17.231411.10943@engage.pko.dec.com>
  9. Reply-To: jamshid@emx.utexas.edu
  10. Organization: The University of Texas at Austin; Austin, Texas
  11. Lines: 42
  12.  
  13. In article <1992Dec17.231411.10943@engage.pko.dec.com> chou@riscee.pko.dec.com (Jesse Chou WSG/SECG) writes:
  14. >This may be a very basic and silly question to ask but I am new to Borland
  15. >c++.  It is greatly appreciated that someone could enlighten me or give me
  16. >pointer to a FAQ.
  17.  
  18. The comp.lang.c++ FAQL is available by anonymous ftp at
  19. sun.soe.clarkson.edu in the file pub/C++/FAQ (though there's not much
  20. on templates).
  21.  
  22. >I am writing a list class using template and got link error:
  23. >Error: Undefined symbol slist_base::append(slink near*) in module tpc.cpp
  24. >I had a similar error using other c++ compiler and found that I have to use
  25. >a command line switch with the compiler.
  26.  
  27. Different compilers currently do not handle the generation of template
  28. functions in the same way.  The ARM leaves a lot unspecified and I'm
  29. not sure what ANSI C++ will say about it.  Make sure you read your
  30. compiler manuals as there are often different ways to do it even with
  31. the same compiler, each method offering different tradeoffs.
  32.  
  33. The easiest way to do deal with this under BC++ (and I believe gcc) is
  34. to just #include the .cpp file containing the non-inline template
  35. functions in the corresponding header file.
  36.  
  37.     // List.h
  38.     #ifndef List_H
  39.     #define List_H
  40.  
  41.     template<class T> class List { /*...*/ };
  42.     //...
  43.  
  44.     #ifndef DONT_NEED_CPP
  45.     #include "List.cpp"
  46.     #endif
  47.  
  48.     #endif // List_H
  49.  
  50. Jamshid Afshar
  51. jamshid@emx.utexas.edu
  52.  
  53.  
  54.  
  55.