home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13228 < prev    next >
Encoding:
Text File  |  1992-09-02  |  1.4 KB  |  61 lines

  1. Path: sparky!uunet!gatech!darwin.sura.net!haven.umd.edu!mimsy!lhc!lhc!warsaw
  2. From: warsaw@nlm.nih.gov (Barry A. Warsaw)
  3. Newsgroups: comp.lang.c++
  4. Subject: External or internal linkage according to ARM?
  5. Message-ID: <WARSAW.92Sep2153003@anthem.nlm.nih.gov>
  6. Date: 2 Sep 92 20:30:03 GMT
  7. Sender: usenet@nlm.nih.gov (usenet news poster)
  8. Reply-To: warsaw@nlm.nih.gov (Barry A. Warsaw)
  9. Organization: Century Computing, Inc.
  10. Lines: 49
  11.  
  12.  
  13. In the following example, should the symbol Singleton::OnlyOne have
  14. external linkage or internal linkage?  Cfront 2.1 say external, but
  15. g++ 2.2.2 gives only internal and the question of which is correct has
  16. come up.
  17.  
  18. ----single.h----
  19. #include <iostream.h>
  20. class Singleton
  21. {
  22. public:
  23.     static const Singleton& const OnlyOne;
  24.     void dosomething() { cout << "doing something" << endl; };
  25. protected:
  26.     Singleton( void ) {};
  27. };
  28.  
  29.  
  30. ----single.cc----
  31. #include "single.h"
  32. class SingletonBuilder : public Singleton
  33. {
  34. public:
  35.     SingletonBuilder( void ) {};
  36. };
  37.  
  38.  
  39. const SingletonBuilder secretlyBuiltByLibrary;
  40. const Singleton& const Singleton::OnlyOne = secretlyBuiltByLibrary;
  41.  
  42.  
  43. ----main.cc----
  44. #include "single.h"
  45. int main( int, char** )
  46. {
  47.     Singleton::OnlyOne.dosomething();
  48.     return( 0 );
  49. };
  50.  
  51.  
  52. Note that with g++ 2.2.2, if I change OnlyOne's definition to:
  53.  
  54.     static const Singleton& /* const */ OnlyOne;
  55.  
  56. (ie no second const), then it compiles fine under g++.  So who's
  57. wrong, cfront or g++?
  58.  
  59. Thanks,
  60. -Barry
  61.