This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problems with templates and gcc


Hi,

I have a problem with the cpp file below.
The idea is to have a first template function with 2 arguments. A second
function has the same name but with 1 argument and call the first function
using his argument and another by default.

The problem is the following:
The code works good if the functions are declared and defined in the class (this
is the configuration activ in the file below).
But, when I try to define the function outside the class, I got an error (see
the defintion in /* */ comments between the class definition and the main
function).

I am using gcc 2.95.2 on Linux (OpenLinux 2.3).
 
Is this a compiler problem or do I not defined correctly the functions outside
the template?


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

#include <iostream.h>

template<class T,bool O> class Dummy
{
  T* tab;
public:
  Dummy(void)  {	tab=new T[25];}
  template<class U,bool b> T* Get(const U &u);
  {
    return(0);
  }
  template<class U> T* Get(const U &u);
  {
    return(Get<U,O>(u));
  }	
  ~Dummy(void)
  {
    delete[] tab;
  }  	
};

/*
template<class T,bool O>  template<class U,bool b>
  T* Get(const U &u)
{
  return(0);
}

template<class T,bool O>  template<class U>
  T* Get(const U &u)
{
  return(Get<U,O>(u));
}
*/

int main(int argc,char* argv[])
{
  Dummy<int,true> dummy;
	
  if(!dummy.Get<int>(5)) cout<<"NULL"<<endl;
  if(!dummy.Get<int,false>(5)) cout<<"NULL"<<endl;		
  return(0);
}
-- 


Ir. Pascal Francq
Researcher
Université Libre de Bruxelles
Faculty of Applied Mechanics
Avenue F.D. Roosevelt, 50
CP 165/41
B-1050 Brussels
BELGIUM
Tel. +32-2-650 47 65
Fax +32-2-650 27 10

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]