Created
February 7, 2024 20:04
-
-
Save ywkaras/ebc6bfbb943acb73c4dfcc174da2e49b to your computer and use it in GitHub Desktop.
Template link hell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat a.cc | |
template <typename T> | |
struct C | |
{ | |
static void f1(); | |
static void f2(); | |
}; | |
void g() | |
{ | |
C<int>::f1(); | |
C<double>::f2(); | |
} | |
$ cat b.cc | |
template <typename T> | |
struct C | |
{ | |
static void f1(); | |
static void f2(); | |
}; | |
template <> void C<int>::f1() {} | |
template<typename T> void C<T>::f2() {} | |
void g(); | |
int main() | |
{ | |
g(); | |
C<double>::f2(); | |
return 0; | |
}; | |
$ gcc -Wall -Wextra -pedantic -c a.cc | |
$ gcc -Wall -Wextra -pedantic -c b.cc | |
$ nm -C a.o | |
0000000000000000 T g() | |
U C<double>::f2() | |
U C<int>::f1() | |
$ nm -C b.o | |
0000000000000007 T main | |
U g() | |
0000000000000000 W C<double>::f2() | |
0000000000000000 T C<int>::f1() | |
$ gcc -Wall -Wextra -pedantic a.o b.o | |
$ ./a.out | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment