error with templates and namespaces

Gary A. Huber ghuber@josquin.ucsd.edu
Thu Nov 4 16:39:00 GMT 1999


Hi, gcc folks,

I have some code that doesn't compile.  Apparently, the using
keyword doesn't work in templated functions.  It compiles
fine using the Kuck and Associates compiler.

I'm using egcs-1.1.2-24 on a Pentium box running Red Hat Linux 6.0
I've also tried it with gcc-2.95.2 and I get the same results.

Below is the command I use, the error messages, and the actual code.

gcc -o gcc_test gcc_test.cc -lstdc++

gcc_test.cc: In function `int g<int>(const int &)':
gcc_test.cc:35:   instantiated from here
gcc_test.cc:17: `f' undeclared (first use this function)
gcc_test.cc:17: (Each undeclared identifier is reported only once
gcc_test.cc:17: for each function it appears in.)

Thanks

Gary

//#########################################################
// gcc_test.cc

#include <stdio.h>

//################
namespace A{

  void f(){
    printf( "f\n");
  }
}

//################
template< class T>
T g( const T& t){

  using namespace A;

  f();
  return t + t;
}

//################
int h( int t){

  using namespace A;

  f();
  return t+t;
}

//################
int main(){

  int i = 2;
  //  int j = h(i);  // this works
  int j = g(i);  // this does not work
}

-------------------------------------------------------------------

Gary A. Huber, Ph.D                     ghuber@ucsd.edu
Assistant Professor                     Phone: (858) 534-4277
Department of Bioengineering            FAX:   (858) 534-6896
University of California San Diego
La Jolla, CA 92093-0412
USA




More information about the Gcc-bugs mailing list