public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13262] New: "xxx is private within this context" when initializing a *self-contained* template class
@ 2003-12-01 17:03 fmonica at ce dot unipr dot it
  2003-12-01 20:57 ` [Bug c++/13262] [3.3/3.4 regression] " bangerth at dealii dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: fmonica at ce dot unipr dot it @ 2003-12-01 17:03 UTC (permalink / raw)
  To: gcc-bugs

This code will compile successful with gcc <= 3.2.3 but doesn't work with gcc 
3.3.1 or 3.3.2: 
----------------------------------------------------- 
template < typename T > 
class Aclass 
  { 
  private: 
    Aclass() {} 
    static Aclass instance; 
  }; 
 
template < typename T > Aclass<T> Aclass<T>::instance; 
 
 
template class Aclass<int>; 
----------------------------------------------------- 
 
The gcc compiler emits an error like this: 
test.cc: In instantiation of `Aclass<int> Aclass<int>::instance': 
test.cc:12:   instantiated from here 
test.cc:5: error: `Aclass<T>::Aclass() [with T = int]' is private 
test.cc:9: error: within this context 
 
This code also works if an explicit instantiation of "instance" is added 
before the last line: 
Aclass<int> Aclass<int>::instance; 
 
That strategy (self contained class with private ctor) will be useful to build 
pattern like "Singleton", proposed by GoF. Of course there are some other ways 
to do this :-) 
 
I'm in doublt, but I think the code should be correct...

-- 
           Summary: "xxx is private within this context" when initializing a
                    *self-contained* template class
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fmonica at ce dot unipr dot it
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13262


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-12-18 14:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-01 17:03 [Bug c++/13262] New: "xxx is private within this context" when initializing a *self-contained* template class fmonica at ce dot unipr dot it
2003-12-01 20:57 ` [Bug c++/13262] [3.3/3.4 regression] " bangerth at dealii dot org
2003-12-02  0:45 ` pinskia at gcc dot gnu dot org
2003-12-02  0:51 ` pinskia at gcc dot gnu dot org
2003-12-05 12:09 ` lerdsuwa at gcc dot gnu dot org
2003-12-15 12:23 ` lerdsuwa at gcc dot gnu dot org
2003-12-18 14:51 ` cvs-commit at gcc dot gnu dot org
2003-12-18 15:26 ` cvs-commit at gcc dot gnu dot org
2003-12-18 15:53 ` lerdsuwa at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).