S
Stanisław Findeisen
#include <iostream>
#include <typeinfo>
extern "C" {
template <typename T> void f() {
const std::type_info& ti(typeid(T));
std::cout << "f(): T is now: " << (ti.name()) << std::endl;
}
}
int main() {
f<int>();
f<std::string>();
return 0;
}
It looks that templates with C linkage don't work in g++:
$ g++ -Wall tmpl1.cpp -o tmpl1.out
tmpl1.cpp:5: error: template with C linkage
.... and are even prohibited by the standard:
========================================================================
A template name has linkage (3.5). A non-member function template can
have internal linkage; any other template name shall have external
linkage. [...] A template, a template explicit specialization (14.7.3),
or a class template partial specialization shall not have C linkage.
========================================================================
Why are they prohibited?
STF
http://eisenbits.homelinux.net/~stf/
OpenPGP: DFD9 0146 3794 9CF6 17EA D63F DBF5 8AA8 3B31 FE8A
#include <typeinfo>
extern "C" {
template <typename T> void f() {
const std::type_info& ti(typeid(T));
std::cout << "f(): T is now: " << (ti.name()) << std::endl;
}
}
int main() {
f<int>();
f<std::string>();
return 0;
}
It looks that templates with C linkage don't work in g++:
$ g++ -Wall tmpl1.cpp -o tmpl1.out
tmpl1.cpp:5: error: template with C linkage
.... and are even prohibited by the standard:
========================================================================
A template name has linkage (3.5). A non-member function template can
have internal linkage; any other template name shall have external
linkage. [...] A template, a template explicit specialization (14.7.3),
or a class template partial specialization shall not have C linkage.
========================================================================
Why are they prohibited?
STF
http://eisenbits.homelinux.net/~stf/
OpenPGP: DFD9 0146 3794 9CF6 17EA D63F DBF5 8AA8 3B31 FE8A