Stupid typedef question / g++

SA bullet.train@ntlworld.com
Fri Jan 24 15:15:00 GMT 2003


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



More information about the Gcc-help mailing list