Why can't I compile the program 1 when the the program 2 is working fine ? Why is it's behavior different?
Program 1:
#include <iostream>
typedef int s1;
typedef int s2;
void print(s1 a){ std::cout << "s1\n"; }
void print(s2 a){ std::cout << "s2\n"; }
int main() {
s1 a;
s2 b;
print(a);
print(b);
return 0;
}
Program 2:
#include <iostream>
typedef struct{int a;} s1;
typedef struct{int a;} s2;
void print(s1 a){ std::cout << "s1\n"; }
void print(s2 a){ std::cout << "s2\n"; }
int main() {
s1 a;
s2 b;
print(a);
print(b);
return 0;
}
This is a bug reproduce from templated class, How can I verify if two template argument are from the same type (in the case of the program 1)