Mail Archives: cygwin/2001/11/02/20:08:35
I adapted some code from Andrei Alexandrescu's Loki class library:
// start of code:
#include <iostream>
using namespace std;
template <typename T, typename U>
class Conversion
{
public:
#ifdef ONE
template <typename T1, typename U1>
class ConversionHelper
{
public:
typedef char Small;
struct Big { char dummy[2]; };
static Big Test(...);
static Small Test(U1);
static T1 MakeT();
};
typedef ConversionHelper<T, U> H;
enum { exists = sizeof(typename H::Small) ==
sizeof(H::Test(H::MakeT())) };
#endif
#ifdef TWO
typedef char Small;
struct Big { char dummy[2]; };
static Big Test(...);
static Small Test(U);
static T MakeT();
enum { exists = sizeof( Small) == sizeof( Test(
MakeT())) };
#endif
enum { exists2Way = exists && Conversion<U, T>::exists };
enum { sameType = false };
};
template <typename T>
class Conversion<T, T>
{
public:
enum { exists = 1, exists2Way = 1,sameType = 1 };
};
int main()
{
cout << Conversion<double, int>::exists;
return 0;
}
// end of code
I'm using g++ version 2.95.3-5.
If I compile -DONE, it compiles and executes OK.
If I compile -DTWO, it gets the following errors:
andrei.cpp: In instantiation of `Conversion<double,int>':
andrei.cpp:44: instantiated from here
andrei.cpp:44: invalid use of undefined type `class
Conversion<double,int>'
andrei.cpp:33: forward declaration of `class Conversion<double,int>'
andrei.cpp:44: invalid use of undefined type `class
Conversion<double,int>'
andrei.cpp:33: forward declaration of `class Conversion<double,int>'
andrei.cpp: In instantiation of `Conversion<int,double>':
andrei.cpp:44: instantiated from `Conversion<double,int>'
andrei.cpp:44: instantiated from here
andrei.cpp:44: invalid use of undefined type `class
Conversion<int,double>'
andrei.cpp:33: forward declaration of `class Conversion<int,double>'
andrei.cpp:44: invalid use of undefined type `class
Conversion<int,double>'
andrei.cpp:33: forward declaration of `class Conversion<int,double>'
I don't understand why replacing the ConversionHelper with its members
causes the errors.
Is this a bug?
Robert Schwartz
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Bug reporting: http://cygwin.com/bugs.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -