cannot compile (formatting a Date/Time as a String)

Asked by Edward Benson

Dear Ubuntu programers by g++:

  I copied a piece simple (Formatting a Date/Time as a String) program
from book(c++ cookbook), chapter5 Section2, Example5-4, on page 201.
on my g++4.5.2(ubuntu10.04, with kernel 2.6.35-25)
you can get that example code from
http://examples.oreilly.com/9780596007614/
to test by yourself

I got compile errors
------------------------
eric@eric-laptop:~/cppcookbook/ch5$ g++ Example5-4.cpp
Example5-4.cpp: In function ‘std::ostream& formatDatetime(std::ostream&,
const tm&, const char*)’:
Example5-4.cpp:16:17: error: invalid use of incomplete type ‘const
struct std::time_put<char>
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/localefwd.h:163:11: error: declaration of ‘const struct
std::time_put<char>
Example5-4.cpp: In function ‘std::string dateTimeToString(const tm&,
const char*)’:
Example5-4.cpp:24:31: error: ‘formatDateTime’ was not declared in this
scope
In file included
from /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/locale_classes.h:815:0,

from /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/ios_base.h:43,

from /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/ios:43,

from /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/ostream:40,

from /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/iostream:40,
                 from Example5-4.cpp:2:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/locale_classes.tcc: In function ‘const _Facet&
std::use_facet(const std::locale&) [with _Facet = std::time_put<char>]’:
Example5-4.cpp:14:77: instantiated from here
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/locale_classes.tcc:107:43: error: incomplete type
‘std::time_put<char>’ used in nested name specifier
/usr/local/lib/gcc/i686-pc-linux-gnu/4.5.2/../../../../include/c
++/4.5.2/bits/locale_classes.tcc:112:56: error: cannot dynamic_cast ‘*
*(__facets + ((unsigned int)(((unsigned int)__i) * 4u)))’ (of type
‘const class std::locale::facet’) to type ‘const struct
std::time_put<char>&’ (target is not pointer or reference to complete
type)
eric@eric-laptop:~/cppcookbook/ch5$
----------------------------------------------------------------
need your help to fix it
and thanks a lot in advance
Eric

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1

Your question was answered on comp.language.c++ .

Can you help with this problem?

Provide an answer of your own, or ask Edward Benson for more information if necessary.

To post a message you must log in.