Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problems compiling templates

Reply
Thread Tools

Problems compiling templates

 
 
jose luis fernandez diaz
Guest
Posts: n/a
 
      05-04-2004
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_3std4pairXTCiTQ 2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3 std4le
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_3 std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std 4lessX
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.
 
Reply With Quote
 
 
 
 
Leor Zolman
Guest
Posts: n/a
 
      05-04-2004
On 4 May 2004 10:21:09 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
 
 
 
Jeff Flinn
Guest
Posts: n/a
 
      05-04-2004

"jose luis fernandez diaz" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed) om...
> 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


 
Reply With Quote
 
Leor Zolman
Guest
Posts: n/a
 
      05-04-2004
On Tue, 4 May 2004 14:17:06 -0400, "Jeff Flinn" <(E-Mail Removed)> wrote:

>
>"jose luis fernandez diaz" <(E-Mail Removed)> wrote in
>message news:(E-Mail Removed) om...
>> 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
 
Reply With Quote
 
jose luis fernandez diaz
Guest
Posts: n/a
 
      05-05-2004
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.

(E-Mail Removed) (jose luis fernandez diaz) wrote in message news:<(E-Mail Removed). com>...
> 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_3std4pairXTCiTQ 2_3std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3 std4le
> 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_3 std3mapXTiTQ2_3std3mapXTiTQ2_3std3mapXTiTiTQ2_3std 4lessX
> 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.

 
Reply With Quote
 
Dave Moore
Guest
Posts: n/a
 
      05-06-2004
(E-Mail Removed) (jose luis fernandez diaz) wrote in message news:<(E-Mail Removed). com>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 09:47 PM
Cross-compiling error when compiling 2.6.1... Garrett Cooper Python 0 02-24-2009 08:55 PM
problems compiling templates with ubuntu c++ Josefo C++ 6 09-15-2006 12:27 AM
how to Specializations of function Templates or Overloading Function templates with Templates ? recover C++ 2 07-25-2006 02:55 AM
Templates templates templates JKop C++ 3 07-21-2004 11:44 AM



Advertisments