This is the mail archive of the gcc-help@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]
Other format: [Raw text]

I can not compile code from <<modern c++ design>>


Hi,

Following code is listed in chapter 2.7 Detecting Convertibility and Inheritance at Compile Time:

#include <iostream>

template <class T, class U>
class Conversion
{
typedef char Small;
class Big { char dummy[2]; };

static Small Test(U);
static Big Test(...);
static T MakeT();

public:
enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
};

int main()
{
using namespace std;

cout<< Conversion<double, int>::exists << ' '<< Conversion<char, char*>::exists;

return 0;
}

and I got following errors:

C:\ttt>gcc -o template template.cpp
template.cpp:5: warning: all member functions in class `Conversion<T, U>' are
   private
template.cpp: In instantiation of `Conversion<double, int>':
template.cpp:21:   instantiated from here
template.cpp:21: invalid use of undefined type `class Conversion<double, int>'
template.cpp:5: declaration of `class Conversion<double, int>'
template.cpp:21: invalid use of undefined type `class Conversion<double, int>'
template.cpp:5: declaration of `class Conversion<double, int>'
template.cpp:21: enumerator value for `exists' not integer constant
template.cpp: In instantiation of `Conversion<char, char*>':
template.cpp:21:   instantiated from here
template.cpp:21: invalid use of undefined type `class Conversion<char, char*>'
template.cpp:5: declaration of `class Conversion<char, char*>'
template.cpp:21: invalid use of undefined type `class Conversion<char, char*>'
template.cpp:5: declaration of `class Conversion<char, char*>'
template.cpp:21: enumerator value for `exists' not integer constant

Anyone can help me?

Thanks!
Di Yang
Best Regards
Di Yang
Phone: 86-10-85296529 ext.130 QUALCOMM CDMA Technologies
Fax: 86-10-85296110 Floor 26th, North Tower, Kerry Center
Mobile: 86-13301338054 No. 1, Guang Hua Road, Chao Yang District
Email: diy at qualcomm dot com Beijing 100020, China



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