public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ porting to GCC problem
@ 2004-11-17 15:11 Alex Bond
  2004-11-17 15:45 ` Eljay Love-Jensen
  2004-11-17 15:59 ` Philippe Haution
  0 siblings, 2 replies; 3+ messages in thread
From: Alex Bond @ 2004-11-17 15:11 UTC (permalink / raw)
  To: gcc-help

Hi,

I'm porting some C++ originally written in Visual Studio to GCC. I've hit 
one snag that I can't explain and I'd like to get some help please!

The following bit of code is a simplified version of the full code, but it 
replicates the essential form of the problem exactly.

When using g++ (v3.3.3 on Cygwin or v3.2 on Redhat) with no extra command 
line options, it produces a parse error at the indicated line. However when 
compiled under Borland 6 or SGI MIPs (with their ANSI switches turned on) it 
compiles with no whinges and produces the right output (the number 2) when 
run.

Is this an illegal bit of syntax permitted by other compilers (I promise 
that there is a good reason for this structure in the original program!), or 
is it a g++ thing?

Thanks in advance


#include <iostream>
using namespace std;
/*------------------------------------*/
class A
{
public:
	enum Fish
	{
		Carp,
		Haddock,
		Cod
	};
};

/*------------------------------------*/
template<class T>
class Z
{
public:
	Z(){}

	int MakeFish()
	{
		T::Fish theFish = T::Cod; <-------------Parse error here before ";"

		cout << theFish << endl;
		return 0;
	}
};

/*------------------------------------*/
int main()
{
	Z<A> hello;

	hello.MakeFish();

	return 0;
}


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

* Re: C++ porting to GCC problem
  2004-11-17 15:11 C++ porting to GCC problem Alex Bond
@ 2004-11-17 15:45 ` Eljay Love-Jensen
  2004-11-17 15:59 ` Philippe Haution
  1 sibling, 0 replies; 3+ messages in thread
From: Eljay Love-Jensen @ 2004-11-17 15:45 UTC (permalink / raw)
  To: Alex Bond, gcc-help

Hi Alex,

On this issue, GCC is compliant to the ISO 14882 standard, the other 
compilers are not.  Change the offending line to...

typename T::Fish theFish = T::Cod;

...and everything should be better.  (And should work on all the 
aforementioned compilers.)

HTH,
--Eljay

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

* Re: C++ porting to GCC problem
  2004-11-17 15:11 C++ porting to GCC problem Alex Bond
  2004-11-17 15:45 ` Eljay Love-Jensen
@ 2004-11-17 15:59 ` Philippe Haution
  1 sibling, 0 replies; 3+ messages in thread
From: Philippe Haution @ 2004-11-17 15:59 UTC (permalink / raw)
  To: Alex Bond; +Cc: gcc-help

Hello,

gcc is right to reject this code, and it will accept :

typename T::Fish theFish = T::Cod;

Regards,

PH
 
--- Alex Bond <alex_bond76@hotmail.com> a écrit : 
> Hi,
> 
> I'm porting some C++ originally written in Visual
> Studio to GCC. I've hit 
> one snag that I can't explain and I'd like to get
> some help please!
> 
> The following bit of code is a simplified version of
> the full code, but it 
> replicates the essential form of the problem
> exactly.
> 
> When using g++ (v3.3.3 on Cygwin or v3.2 on Redhat)
> with no extra command 
> line options, it produces a parse error at the
> indicated line. However when 
> compiled under Borland 6 or SGI MIPs (with their
> ANSI switches turned on) it 
> compiles with no whinges and produces the right
> output (the number 2) when 
> run.
> 
> Is this an illegal bit of syntax permitted by other
> compilers (I promise 
> that there is a good reason for this structure in
> the original program!), or 
> is it a g++ thing?
> 
> Thanks in advance
> 
> 
> #include <iostream>
> using namespace std;
> /*------------------------------------*/
> class A
> {
> public:
> 	enum Fish
> 	{
> 		Carp,
> 		Haddock,
> 		Cod
> 	};
> };
> 
> /*------------------------------------*/
> template<class T>
> class Z
> {
> public:
> 	Z(){}
> 
> 	int MakeFish()
> 	{
> 		T::Fish theFish = T::Cod; <-------------Parse
> error here before ";"
> 
> 		cout << theFish << endl;
> 		return 0;
> 	}
> };
> 
> /*------------------------------------*/
> int main()
> {
> 	Z<A> hello;
> 
> 	hello.MakeFish();
> 
> 	return 0;
> }
> 
> 
>  


	
	
		
Vous manquez dÂ’espace pour stocker vos mails ? 
Yahoo! Mail vous offre GRATUITEMENT 100 Mo !
Créez votre Yahoo! Mail sur http://fr.benefits.yahoo.com/

Le nouveau Yahoo! Messenger est arrivé ! Créez vos avatars et envoyez des audiofuns. Découvrez toutes les nouveautés en le téléchargeant sur : http://fr.messenger.yahoo.com

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

end of thread, other threads:[~2004-11-17 15:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-17 15:11 C++ porting to GCC problem Alex Bond
2004-11-17 15:45 ` Eljay Love-Jensen
2004-11-17 15:59 ` Philippe Haution

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