This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Stupid typedef question / g++


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]