www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/11/18:30:16

From: "Steve Ball" <steve AT effectivejava DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Can't specify initial value for template static fields
Date: Mon, 12 Jul 1999 09:22:03 +1200
Organization: Customer of Telecom Internet Services
Lines: 31
Message-ID: <7mb1u0$4pr21$1@titan.xtra.co.nz>
NNTP-Posting-Host: 210-55-123-47.dialup.xtra.co.nz
X-Trace: titan.xtra.co.nz 931728128 5041217 210.55.123.47 (11 Jul 1999 21:22:08 GMT)
X-Complaints-To: abuse AT xtra DOT co DOT nz
NNTP-Posting-Date: 11 Jul 1999 21:22:08 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Is there any reason why I can't specify an initial value for a static field
of a templated class?

template <typename T>
class X {
public:
    static int n;
};

template <typename T>
int X<T>::n;

void main()
{
    X<int> t;
    cout << t.n;
}

This works fine, but if n is given an initial value:

template <typename T>
int X<T>::n = 1;

then the linker complains that X<int>::n is an undefined symbol.

What am I missing here?





- Raw text -


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