Please consider the code:
#include using namespace std; extern \"C\" void foo( void ); namespace A { template< int No >
You need to declare the friend as extern "C". Your current friend declaration finds a friend foo in the global namespace that has C++ name mangling.