🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #798

g++ 2.2.2 and template syntax?

#798
From: Barry A. Warsaw
Date: Fri, 28 Aug 1992 16:50
129 lines
2523 bytes
Is there a difference between the template syntax that g++ 2.2.2
parses and that which the ARM specifies?  I'm a template novice so
apologies if its me that's confused.

The following program illustrates the problem.  Compile with no
switches to watch it work.  Compile with -DARMTEMPLATES to compile
with (my understanding of) ARM syntax for the copy constructor of a
template class.  Compile instead with -DCOMPLAIN to see that, even
though (I think) g++ doesn't parse the correct syntax, it does do The
Right Thing.

In brief, should the copy ctor of a template class look like:

template<class Thing>
class Printer
{
public:
	Printer( Printer<Thing>& copy );
};

as my reading of the ARM indicates, or should it be:

template<class Thing>
class Printer
{
public:
	Printer( Printer& copy );
};

as g++ seems to want?

Thanks,
-Barry

-------------------- snip snip --------------------
#include <iostream.h>

#ifdef ARMTEMPLATES
#define SCOPEDTHING(c,t) c<t>
#else
#define SCOPEDTHING(c,t) c
#endif


template<class Thing>
class Printer
{
public:
	Printer( Thing& t );
	Printer( SCOPEDTHING(Printer,Thing)& copy );

	void whoami( void ) const
	{
		cout << "I am " << xt.who << endl;
	};

private:
	Thing& xt;
};


template<class Thing>
Printer<Thing>::Printer( Thing& t )
	: xt( t )
{};


template<class Thing>
Printer<Thing>::Printer( SCOPEDTHING(Printer,Thing)& copy )
	: xt( copy.xt )
{};


class Zero
{
public:
	char* who;
	Zero( void )
		: who( "zero" )
	{};
};


class One
{
public:
	char* who;
	One( void )
		: who( "one" )
	{};
};


class Two
{
public:
	char* who;
	Two( void )
		: who( "two" )
	{};
};


int main( int, char** )
{
	Zero zero;
	One one;
	Two two;
	Zero another;

	Printer<Zero> z( zero );
	Printer<One> o( one );
	Printer<Two> t( two );
	Printer<Zero> a( another );
	Printer<Zero> b( z );
#ifdef COMPLAIN
	Printer<Zero> c( o );
#endif COMPLAIN

	z.whoami();
	o.whoami();
	t.whoami();
	a.whoami();
	b.whoami();

	return( 0 );
};

	
Technical Details
Message-ID: <WARSAW.92Aug28115053@anthem.nlm.nih.gov>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!nlm.NIh.GOV!warsaw

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!nlm.NIh.GOV!warsaw
From: warsaw@nlm.NIh.GOV (Barry A. Warsaw)
Subject: g++ 2.2.2 and template syntax?
Message-ID: <WARSAW.92Aug28115053@anthem.nlm.nih.gov>
Sender: gnulists@ai.mit.edu
Organization: Century Computing, Inc.
Distribution: gnu
Date: Fri, 28 Aug 1992 16:50:53 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 130