This is the mail archive of the gcc-bugs@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]

Template specialisation



I have the following code :

// BEGIN File.C

template<class Type> class aClass
{
public:
  operator const Type() const
    {
      return aValue;
    }
private:
  Type aValue;
};

class aClass<int>
{
public:
  operator const int() const
    {
      return aValue;
    }
private:
  int aValue;
};

void func(const aClass<bool> & foo_1)
{
  bool bar_1;
  bar_1 = foo_1;
  bar_1 = foo_1 && true;
}

int main()
{
  aClass<bool> foo_1;
  bool bar_1;
  bar_1 = foo_1;

  func(foo_1);
}

// END File.C

This code does not compile. The error message is :
In function `void func(const aClass<bool> &)':
`const class aClass<bool>' used where a `bool' was expected

If I replace func with this version :

void func(const aClass<bool> & foo_1)
{
  bool bar_1;
  bar_1 = foo_1 && true; // switch last 2 lines !!
  bar_1 = foo_1;
}

It compiles and runs correct.  This looks at least a bit weird to me.

compiler : gcc-2.95 gcc-2.95.1 and gcc-2.95.2
platforms : linux redhat 6.0 on a pentium II 366 Mhz
               solaris 2.7 on a sun ultra 5
compile command : g++ file.C

Kind regards,

Steven.


--
===================================================================
Steven Coenen             ===              Easics               ===
ASIC Designer             ===   System-on-Chip design services  ===
Tel: +32-16-395 615          ===================================
Fax: +32-16-395 619      Interleuvenlaan 86, B-3001 Leuven, BELGIUM
mailto:steven@easics.be            http://www.easics.com




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