Problems compiling templates

Discussion in 'C++' started by jose luis fernandez diaz, May 4, 2004.

  1. Hi,

    When I compiling the program below:

    #include <map>

    using namespace std;

    template<typename td1, typename td2, typename td3,typename td4>
    class Tarificador
    {
    public:
    typedef std::map<td4, int> mapD4;
    typedef std::map<td3, mapD4> mapD3;
    typedef std::map<td2, mapD3> mapD2;
    typedef std::map<td1, mapD2> mapD1;

    mapD1 listaTarifas;
    };


    int main()
    {
    Tarificador<int, int, int ,int> t1;

    return 0;
    }


    the next messages are shown:

    Error 849: Exact position unknown; near ["foo.C", line 18]. # External
    symbol too long, truncated from 6599
    to 4000 bytes,
    __ct__Q2_4__rw14__rw_tree_iterXTQ2_3std4pairXTCiTQ2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std4le
    ssXTi_TQ2_3std9allocat...


    Error 849: Exact position unknown; near ["foo.C", line 18]. # External
    symbol too long, truncated from 4982
    to 4000 bytes,
    erase__Q2_4__rw9__rb_treeXTiTQ2_3std4pairXTCiTQ2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std4lessX
    Ti_TQ2_3std9allocatorX...


    If I change the program:

    // typedef std::map<td4, int> mapD4;
    typedef std::map<td3, int> mapD3;

    it compiles fine. I guess that the problem is that there is a limit in
    the definition of recursive templates.

    My OS and compiler are:

    cronos:jdiaz:tmp>uname -a
    HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license
    cronos:jdiaz:tmp>aCC -V
    aCC: HP ANSI C++ B3910B A.03.37



    How can I fix this problem ?

    Thanks,
    Jose Luis.
    jose luis fernandez diaz, May 4, 2004
    #1
    1. Advertising

  2. jose luis fernandez diaz

    Leor Zolman Guest

    On 4 May 2004 10:21:09 -0700, (jose luis
    fernandez diaz) wrote:

    >If I change the program:
    >
    >// typedef std::map<td4, int> mapD4;
    > typedef std::map<td3, int> mapD3;
    >
    >it compiles fine. I guess that the problem is that there is a limit in
    >the definition of recursive templates.
    >


    FWIW, this compiles fine with every single PC-based platform I have...so it
    definitely looks like an arbitrary limitation on the size of type names in
    your compiler. I'd look for options to raise that limit, or else for a new
    compiler (gcc is among those that have no problem, and you can probably
    find a version of that for your platform.)
    -leor

    --
    Leor Zolman --- BD Software --- www.bdsoft.com
    On-Site Training in C/C++, Java, Perl and Unix
    C++ users: download BD Software's free STL Error Message Decryptor at:
    www.bdsoft.com/tools/stlfilt.html
    Leor Zolman, May 4, 2004
    #2
    1. Advertising

  3. jose luis fernandez diaz

    Jeff Flinn Guest

    "jose luis fernandez diaz" <> wrote in
    message news:...
    > Hi,
    >
    > When I compiling the program below:
    >
    > #include <map>
    >
    > using namespace std;
    >
    > template<typename td1, typename td2, typename td3,typename td4>
    > class Tarificador
    > {
    > public:
    > typedef std::map<td4, int> mapD4;
    > typedef std::map<td3, mapD4> mapD3;
    > typedef std::map<td2, mapD3> mapD2;
    > typedef std::map<td1, mapD2> mapD1;
    >
    > mapD1 listaTarifas;
    > };
    >
    >
    > int main()
    > {
    > Tarificador<int, int, int ,int> t1;
    >
    > return 0;
    > }
    >
    >
    > the next messages are shown:
    >
    > Error 849: Exact position unknown; near ["foo.C", line 18]. # External


    "foo.C"? are you compiling this with a C compiler?

    Jeff F
    Jeff Flinn, May 4, 2004
    #3
  4. jose luis fernandez diaz

    Leor Zolman Guest

    On Tue, 4 May 2004 14:17:06 -0400, "Jeff Flinn" <> wrote:

    >
    >"jose luis fernandez diaz" <> wrote in
    >message news:...
    >> Hi,
    >>
    >> When I compiling the program below:
    >>
    >> #include <map>
    >>
    >> using namespace std;
    >>
    >> template<typename td1, typename td2, typename td3,typename td4>
    >> class Tarificador
    >> {
    >> public:
    >> typedef std::map<td4, int> mapD4;
    >> typedef std::map<td3, mapD4> mapD3;
    >> typedef std::map<td2, mapD3> mapD2;
    >> typedef std::map<td1, mapD2> mapD1;
    >>
    >> mapD1 listaTarifas;
    >> };
    >>
    >>
    >> int main()
    >> {
    >> Tarificador<int, int, int ,int> t1;
    >>
    >> return 0;
    >> }
    >>
    >>
    >> the next messages are shown:
    >>
    >> Error 849: Exact position unknown; near ["foo.C", line 18]. # External

    >
    >"foo.C"? are you compiling this with a C compiler?


    Capital "C", not unusual for C++ source. Besides, how many C compilers can
    you name that would produce messages containing stuff like
    "symbol too long, truncated from 6599 to 4000 bytes"
    and show a clearly mangled name? ;-)
    -leor

    >
    >Jeff F
    >


    --
    Leor Zolman --- BD Software --- www.bdsoft.com
    On-Site Training in C/C++, Java, Perl and Unix
    C++ users: download BD Software's free STL Error Message Decryptor at:
    www.bdsoft.com/tools/stlfilt.html
    Leor Zolman, May 4, 2004
    #4
  5. Hi,

    I have found the solution on Intenet:

    > The problem is that you've got a data structure that contains
    > several STL
    > types, and the mangled name is too long for aCC. For
    > example, you may have:
    >
    > map<string,string> mymap;
    >
    > To work around this, define your own type:
    >
    > class mymap_t : public map<string,string> {};
    > mymap_t map;
    >
    > It must be a class, not simply a typedef. The mangled name for mymap_t
    > is now quite small. Of course, mymap_t doesn't inherit all of the
    > constructors that map<> has, but you can write forwarding constructors
    > as needed.



    I hope that this be useful for other people.

    Regars,
    Jose Luis.

    (jose luis fernandez diaz) wrote in message news:<>...
    > Hi,
    >
    > When I compiling the program below:
    >
    > #include <map>
    >
    > using namespace std;
    >
    > template<typename td1, typename td2, typename td3,typename td4>
    > class Tarificador
    > {
    > public:
    > typedef std::map<td4, int> mapD4;
    > typedef std::map<td3, mapD4> mapD3;
    > typedef std::map<td2, mapD3> mapD2;
    > typedef std::map<td1, mapD2> mapD1;
    >
    > mapD1 listaTarifas;
    > };
    >
    >
    > int main()
    > {
    > Tarificador<int, int, int ,int> t1;
    >
    > return 0;
    > }
    >
    >
    > the next messages are shown:
    >
    > Error 849: Exact position unknown; near ["foo.C", line 18]. # External
    > symbol too long, truncated from 6599
    > to 4000 bytes,
    > __ct__Q2_4__rw14__rw_tree_iterXTQ2_3std4pairXTCiTQ2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std4le
    > ssXTi_TQ2_3std9allocat...
    >
    >
    > Error 849: Exact position unknown; near ["foo.C", line 18]. # External
    > symbol too long, truncated from 4982
    > to 4000 bytes,
    > erase__Q2_4__rw9__rb_treeXTiTQ2_3std4pairXTCiTQ2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std4lessX
    > Ti_TQ2_3std9allocatorX...
    >
    >
    > If I change the program:
    >
    > // typedef std::map<td4, int> mapD4;
    > typedef std::map<td3, int> mapD3;
    >
    > it compiles fine. I guess that the problem is that there is a limit in
    > the definition of recursive templates.
    >
    > My OS and compiler are:
    >
    > cronos:jdiaz:tmp>uname -a
    > HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license
    > cronos:jdiaz:tmp>aCC -V
    > aCC: HP ANSI C++ B3910B A.03.37
    >
    >
    >
    > How can I fix this problem ?
    >
    > Thanks,
    > Jose Luis.
    jose luis fernandez diaz, May 5, 2004
    #5
  6. jose luis fernandez diaz

    Dave Moore Guest

    (jose luis fernandez diaz) wrote in message news:<>...
    > Hi,
    >
    > I have found the solution on Intenet:
    >
    > > The problem is that you've got a data structure that contains
    > > several STL
    > > types, and the mangled name is too long for aCC. For
    > > example, you may have:
    > >
    > > map<string,string> mymap;
    > >
    > > To work around this, define your own type:
    > >
    > > class mymap_t : public map<string,string> {};
    > > mymap_t map;
    > >
    > > It must be a class, not simply a typedef. The mangled name for mymap_t
    > > is now quite small. Of course, mymap_t doesn't inherit all of the
    > > constructors that map<> has, but you can write forwarding constructors
    > > as needed.

    >
    >
    > I hope that this be useful for other people.
    >
    > > Jose Luis.


    Well, just to be clear .. the proposed solution has some problems as
    well, because it can be a risky practice to derive from the STL
    containers, which lack virtual destructors. Therefore, it is much
    safer to include the STL container as a data member, and then use
    forwarding functions to access it. This is a pain to code up, but
    unless you can guarantee that you will never "slice" the derived
    object (i.e. delete it through a pointer to the base type), then you
    can't really get around this. Note that if you give your wrapper
    class a proper virtual dtor, then you can safely derive from it.

    There are plenty of other articles in c.l.c++ and related NG's where
    you can get more info, and you might want to check the GotW archives
    also. (http://www.gotw.ca/gotw/index.htm)

    HTH, Dave Moore
    Dave Moore, May 6, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    3
    Views:
    449
  2. Susan Baker
    Replies:
    2
    Views:
    800
    kelvSYC
    Jun 26, 2005
  3. recover
    Replies:
    2
    Views:
    782
    recover
    Jul 25, 2006
  4. Josefo
    Replies:
    6
    Views:
    362
    Jacek Dziedzic
    Sep 15, 2006
  5. Garrett Cooper
    Replies:
    0
    Views:
    539
    Garrett Cooper
    Feb 24, 2009
Loading...

Share This Page