This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/588: defining static data member of template class needs initializer



>Number:         588
>Category:       c++
>Synopsis:       defining static data member of template class needs initializer
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun Oct 01 10:06:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     brianchon@sina.com
>Release:        unknown-1.0
>Organization:
>Environment:
cygwin, mingw32
>Description:
when using template specialization syntax to define a static data member of a class template, an initializer must be supplied, otherwise a "not defined" linkage error will occur.
>How-To-Repeat:
template<typename T>
class A {
public:
    static T x;
    T GetX() {return x;}
};

template<> int A<int>::x; // linkage error
//int A<int>::x; this one is OK
//template<> int A<int>::x = 0; is OK too.

int main()
{
    A<int> a;

    return a.GetX();
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]