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]

Template specialisation problem


I have the following code :

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);
}

This code does not compile. The error message is :
In function `void func(const C_4<bool> &)':
`const class C_4<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.  Am I doing something wrong here ??

compiler : gcc-2.95 gcc-2.95.1 and gcc-2.95.2
platform : 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.

S/MIME Cryptographic Signature


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