public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/5018: cannot define template member outside class declarations
@ 2001-12-14  1:21 lerdsuwa
  0 siblings, 0 replies; 3+ messages in thread
From: lerdsuwa @ 2001-12-14  1:21 UTC (permalink / raw)
  To: gcc-bugs, gcc-gnats, gcc-prs, nobody, rmaddox

Synopsis: cannot define template member outside class declarations

State-Changed-From-To: open->closed
State-Changed-By: lerdsuwa
State-Changed-When: Fri Dec 14 01:21:34 2001
State-Changed-Why:
    Not a bug.  The correct syntax is
      template <typename T1>
      template <typename T2>
      void Test<T1>::Write(const T2 & value)
      {
    There is no '<T2>' after 'Write'.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=5018&database=gcc


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

* Re: c++/5018: cannot define template member outside class declarations
@ 2001-12-14  1:26 lerdsuwa
  0 siblings, 0 replies; 3+ messages in thread
From: lerdsuwa @ 2001-12-14  1:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR c++/5018; it has been noted by GNATS.

From: lerdsuwa@gcc.gnu.org
To: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
  nobody@gcc.gnu.org, rmaddox@isicns.com
Cc:  
Subject: Re: c++/5018: cannot define template member outside class declarations
Date: 14 Dec 2001 09:21:35 -0000

 Synopsis: cannot define template member outside class declarations
 
 State-Changed-From-To: open->closed
 State-Changed-By: lerdsuwa
 State-Changed-When: Fri Dec 14 01:21:34 2001
 State-Changed-Why:
     Not a bug.  The correct syntax is
       template <typename T1>
       template <typename T2>
       void Test<T1>::Write(const T2 & value)
       {
     There is no '<T2>' after 'Write'.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=5018&database=gcc


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

* c++/5018: cannot define template member outside class declarations
@ 2001-12-05  5:56 rmaddox
  0 siblings, 0 replies; 3+ messages in thread
From: rmaddox @ 2001-12-05  5:56 UTC (permalink / raw)
  To: gcc-gnats


>Number:         5018
>Category:       c++
>Synopsis:       cannot define template member outside class declarations
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Wed Dec 05 05:56:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Randy Maddox
>Release:        3.0.2
>Organization:
>Environment:
Windows 2000
>Description:
Given a template class with a template member it is not possible to define the template member outside of the class declarations.  Defining the template member inside the class declarations works as expected.  The syntax used appears legal as per the Standard and the error reported seems like a mistake since the compiler message states that the definition is a "partial specialization".  Sample source (short) to duplicate problem and output from compiler is given in "How-To-Repeat".
>How-To-Repeat:
- This compiles fine and works as expected:

// test driver for template class template member

#include <iostream>

template <typename T1> class Test
{
public:

  Test(const T1 & privateValue)
    : privateValue_(privateValue)
  { }

  template <typename T2>
  void Write(const T2 & value)
  {
    std::cout << "Write() value is:  " << value << std::endl;
    std::cout << "privateValue is:   " << privateValue_ << std::endl
              << std::endl;
  }

private:

  const T1    privateValue_;
};

int main()
{
  std::cout << "Start of test driver" << std::endl << std::endl;

  Test<double>    test(3.3);

  test.Write("string value");

  test.Write(4);

  std::cout << std::endl << "End of test driver" << std::endl;
}

// end of this file


However, if I try to move the definition of Write() outside of the class declarations as shown here:

// test driver for template class template member

#include <iostream>

template <typename T1> class Test
{
public:

  Test(const T1 & privateValue)
    : privateValue_(privateValue)
  { }

  template <typename T2>
  void Write(const T2 & value);

private:

  const T1    privateValue_;
};


template <typename T1>
template <typename T2>
void Test<T1>::Write<T2>(const T2 & value)
{
  std::cout << "Write() value is:  " << value << std::endl;
  std::cout << "privateValue is:   " << privateValue_ << std::endl
            << std::endl;
}


int main()
{
  std::cout << "Start of test driver" << std::endl << std::endl;

  Test<double>    test(3.3);

  test.Write("string value");

  test.Write(4);

  std::cout << std::endl << "End of test driver" << std::endl;
}

// end of this file


Then I get the following compile error:

> gxx -Wall test2.cpp
test2.cpp:25: partial specialization `Write<T2>' of function template

Since, as far as I can tell from the Standard, this looks like the correct syntax why do I get this error?  Is this a bug?  An unsupported feature?  Or do I just not actually understand the syntax?

>Fix:

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


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

end of thread, other threads:[~2001-12-14  9:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-14  1:21 c++/5018: cannot define template member outside class declarations lerdsuwa
  -- strict thread matches above, loose matches on Subject: below --
2001-12-14  1:26 lerdsuwa
2001-12-05  5:56 rmaddox

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).