I can not compile code from <<modern c++ design>>
Di Yang
diy@qualcomm.com
Tue Apr 8 09:13:00 GMT 2003
>Hi,
>
>i'am confused. Your changes shows that I'm wrong. But i' cant see why.
>You could also change your first version making all members public:
>
>class Conversion
>{
>public:
> typedef char Small;
> class Big { char dummy[2]; };
>
> static Small Test(U);
> static Big Test(...);
> static T MakeT();
>
> enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
>};
>
>which also works.
Sorry, but I still failed at this point:
#include <iostream>
template <class T, class U>
class Conversion
{
public:
typedef char Small;
class Big { char dummy[2]; };
static Small Test(U);
static Big Test(...);
static T MakeT();
enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
};
int main()
{
using namespace std;
cout<< Conversion<double, int>::exists << ' '<< Conversion<char,
char*>::exists;
return 0;
}
Same errror as before:
C:\ttt>g++ -o template template.cpp
template.cpp: In instantiation of `Conversion<double, int>':
template.cpp:42: instantiated from here
template.cpp:42: invalid use of undefined type `class Conversion<double, int>'
template.cpp:5: declaration of `class Conversion<double, int>'
template.cpp:42: invalid use of undefined type `class Conversion<double, int>'
template.cpp:5: declaration of `class Conversion<double, int>'
template.cpp:42: enumerator value for `exists' not integer constant
template.cpp: In instantiation of `Conversion<char, char*>':
template.cpp:42: instantiated from here
template.cpp:42: invalid use of undefined type `class Conversion<char, char*>'
template.cpp:5: declaration of `class Conversion<char, char*>'
template.cpp:42: invalid use of undefined type `class Conversion<char, char*>'
template.cpp:5: declaration of `class Conversion<char, char*>'
template.cpp:42: enumerator value for `exists' not integer constant
C:\ttt>g++ -dumpversion
3.2
C:\ttt>
Only with the Conversionhelper version works for me.
Thanks.
Di
>So, if the initialization of the enum is legal it should be legal in
>your previous version having only the enum public.
>
>cu
>Matthias
More information about the Gcc-help
mailing list