This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Stupid typedef question / g++
- From: Sebastian Huber <sebastian-huber at web dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 24 Jan 2003 17:53:16 +0100
- Subject: Re: Stupid typedef question / g++
- References: <200301241517.27441.bullet.train@ntlworld.com>
Hi,
typedefs provide only type aliasses, they do not define new types. User
defined types can be created via class (or struct) and in a more limited way
with enums.
On Friday 24 January 2003 16:17, SA wrote:
> Should this work?
>
> // start
> #include <stdio.h>
> typedef int TYPE1;
> typedef int TYPE2;
>
> void test(TYPE1);
> void test(TYPE2);
>
> void test(TYPE1 in){
> printf("Called via type1 %d\n",(int)in);
> }
>
> void test(TYPE2 in){
> printf("Called vis type2 %d\n",(int)in);
> }
>
> main(){
> test((TYPE1)10);
> test((TYPE2)20);
> }
> // finish
>
> Now I expected the typedefs and casts to enable correct function selection
> but what I got was
>
> g++ test.cc
> test.cc: In function `void test (int)':
> test.cc:12: redefinition of `void test (int)'
> test.cc:8: `void test (int)' previously defined here
>
> Which is what I would expect if I had used
> #define TYPE1 int
> #define TYPE2 int
> instead?
>
> Comments, suggestions? I wanted to use the typedefing to control the
> function calling for elegance in my program.
>
> Thanks SA