• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Namespace problem with gcc
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Namespace problem with gcc


  • Subject: Re: Namespace problem with gcc
  • From: Adin Hunter Baber <email@hidden>
  • Date: Fri, 22 Jun 2007 11:37:15 -0500


On 2007 Jun 22, at 10:48, Michael Gaines wrote:

Hi everyone,
  I came across this problem when trying to compile some code that works in Visual Studio but not Xcode/gcc. Apparently, from what I read, this SHOULD be valid in C++ but gcc doesn't seem to like it. Here's a sample:

#include <stdio.h>

typedef enum _Type {
  HEY, JUDE
} Type;

typedef struct _object {
  int object_number;
  int generation_number;
  Type Type;
}object;

main()
{
printf("Hello, world!\n");
}

If I save the file as "main.cpp" and compiled for C++, I get:

main.cpp:10: error: declaration of 'Type _object::Type'
main.cpp:5: error: changes meaning of 'Type' from 'typedef enum _Type Type'

If I save the file as "main.c", it builds fine.

Doing some research I found that C has different namespaces for types and variables, but C++ didn't originally. The book I found this in said that it should have been incorporated into C++ but I think gcc doesn't have this fix. So, the question is, how can I fix it? I can't find anything in the Xcode or gcc docs to solve this problem, short of changing the names of the types (why someone did it like this to begin with I don't know). Thanks.


The problem goes away if inside struct _object you replace
Type Type;
with
Type type;

Also, main() requires a return type of int.

Adin Hunter Baber
email@hidden

"If you don't fail 90% of the time, you're not setting your standards high enough."

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Namespace problem with gcc (From: Michael Gaines <email@hidden>)

  • Prev by Date: Re: Crash report doesn't list function names?
  • Next by Date: Re[2]: Crash report doesn't list function names?
  • Previous by thread: Namespace problem with gcc
  • Next by thread: can't get debugger to stop on brakepoint
  • Index(es):
    • Date
    • Thread