Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #7715 > unrolled thread

in g++(invalid use of incomplete type)

Started byeric <cneric12lin0@gmail.com>
First post2011-07-10 23:32 -0700
Last post2011-07-11 20:54 +1200
Articles 4 — 3 participants

Back to article view | Back to comp.lang.c++


Contents

  in g++(invalid use of incomplete type) eric <cneric12lin0@gmail.com> - 2011-07-10 23:32 -0700
    Re: in g++(invalid use of incomplete type) eric <cneric12lin0@gmail.com> - 2011-07-11 00:31 -0700
      Re: in g++(invalid use of incomplete type) Michael DOUBEZ <michael.doubez@free.fr> - 2011-07-11 01:54 -0700
      Re: in g++(invalid use of incomplete type) Ian Collins <ian-news@hotmail.com> - 2011-07-11 20:54 +1200

#7715 — in g++(invalid use of incomplete type)

Fromeric <cneric12lin0@gmail.com>
Date2011-07-10 23:32 -0700
Subjectin g++(invalid use of incomplete type)
Message-ID<e56f2431-3294-45f1-a5c5-7c0cf172fd96@k19g2000prn.googlegroups.com>
Dear c++ programers:

  If you are also an g++ programers, especially ever create/modify its
source code, I need your help
I have a piece simple code about formatting a date/time as a string
from a book.  its authors claim it work in vc++7.1 on xp.
but my g++4.5.2 didn't pass it on compile stage
-------------------------------------------------------------------------------------------
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$
------------------------------------------------------------------------------------------------------------------------------------------------------
I welcome anyone can leading me to modify the source code as well as
any short method to get around it.
thanks a lot in advance
Eric

[toc] | [next] | [standalone]


#7722

Fromeric <cneric12lin0@gmail.com>
Date2011-07-11 00:31 -0700
Message-ID<9216c5aa-78f7-43cd-9957-dea63f1b5a84@34g2000pru.googlegroups.com>
In reply to#7715
On Jul 10, 11:32 pm, eric <cneric12l...@gmail.com> wrote:
> Dear c++ programers:
>
>   If you are also an g++ programers, especially ever create/modify its
> source code, I need your help
> I have a piece simple code about formatting a date/time as a string
> from a book.  its authors claim it work in vc++7.1 on xp.
> but my g++4.5.2 didn't pass it on compile stage
> -------------------------------------------------------------------------------------------
> 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$
> ------------------------------------------------------------------------------------------------------------------------------------------------------
> I welcome anyone can leading me to modify the source code as well as
> any short method to get around it.
> thanks a lot in advance
> Eric

-----------------------------------------------------the program I
used to compile is-----------------------
// Example 5-4 formatting a datetime string
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <string>
#include <stdexcept>
#include <iterator>
#include <sstream>

using namespace std;

ostream& formatDatetime(ostream& out, const tm& t, const char* fmt) {
  const time_put<char>& dateWriter = use_facet<time_put<char>
>(out.getloc());
  int n = strlen(fmt);
  if (dateWriter.put(out, out, ' ', &t, fmt, fmt + n).failed()) {
     throw runtime_error("failure to format date time");
  }
  return out;
 }

string dateTimeToString(const tm& t, const char* format) {
   stringstream s;
   formatDateTime(s, t, format);
   return s.str();
 }

tm now() {
   time_t now = time(0);
   return *localtime(&now);
}

int main()
{
  try {
    string s=dateTimeToString(now(), "%A %B, %d %Y %I:%M%p");
    cout << s << endl;
    s=dateTimeToString(now(), "%Y-%m-%d %H:%M:%S");
    cout << s << endl;
  }
  catch(...) {
    cerr << "failed to format date time" << endl;
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}
--------------------------------------------------------------
or you can get from its download site
http://examples.oreilly.com/9780596007614/
5-4.cpp

[toc] | [prev] | [next] | [standalone]


#7723

FromMichael DOUBEZ <michael.doubez@free.fr>
Date2011-07-11 01:54 -0700
Message-ID<13a34610-cf63-45a5-a952-8bc0fa50e295@hd10g2000vbb.googlegroups.com>
In reply to#7722
On Jul 11, 9:31 am, eric <cneric12l...@gmail.com> wrote:
> On Jul 10, 11:32 pm, eric <cneric12l...@gmail.com> wrote:
[snip]
> > I have a piece simple code about formatting a date/time as a string
> > from a book.  its authors claim it work in vc++7.1 on xp.
> > but my g++4.5.2 didn't pass it on compile stage
> > -------------------------------------------------------------------------------------------
> > 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$
> > ------------------------------------------------------------------------------------------------------------------------------------------------------
> > I welcome anyone can leading me to modify the source code as well as
> > any short method to get around it.
[...]
> #include <cstdlib>
> #include <ctime>
> #include <cstring>
> #include <string>
> #include <stdexcept>
> #include <iterator>
> #include <sstream>

#include <locale>

--
Michael

[toc] | [prev] | [next] | [standalone]


#7724

FromIan Collins <ian-news@hotmail.com>
Date2011-07-11 20:54 +1200
Message-ID<97vs3fF61iU1@mid.individual.net>
In reply to#7722
On 07/11/11 07:31 PM, eric wrote:
>
> -----------------------------------------------------the program I
> used to compile is-----------------------
> // Example 5-4 formatting a datetime string
> #include<iostream>
> #include<cstdlib>
> #include<ctime>
> #include<cstring>
> #include<string>
> #include<stdexcept>
> #include<iterator>
> #include<sstream>
>
> using namespace std;
>
> ostream&  formatDatetime(ostream&  out, const tm&  t, const char* fmt) {
>    const time_put<char>&  dateWriter = use_facet<time_put<char>
>> (out.getloc());

In which standard header is time_put declared?  Check for balance of < 
and >.

>    int n = strlen(fmt);
>    if (dateWriter.put(out, out, ' ',&t, fmt, fmt + n).failed()) {
>       throw runtime_error("failure to format date time");
>    }
>    return out;
>   }
>
> string dateTimeToString(const tm&  t, const char* format) {
>     stringstream s;
>     formatDateTime(s, t, format);

Names are case sensitive!

>     return s.str();
>   }


-- 
Ian Collins

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.c++


csiph-web