By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,610 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,610 IT Pros & Developers. It's quick & easy.

Problems compiling templates

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 4 May 2004 10:21:09 -0700, jo**********************@yahoo.es (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
Jul 22 '05 #2

P: n/a

"jose luis fernandez diaz" <jo**********************@yahoo.es> wrote in
message news:c2**************************@posting.google.c 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
Jul 22 '05 #3

P: n/a
On Tue, 4 May 2004 14:17:06 -0400, "Jeff Flinn" <NO****@nowhere.com> wrote:

"jose luis fernandez diaz" <jo**********************@yahoo.es> wrote in
message news:c2**************************@posting.google.c 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
Jul 22 '05 #4

P: n/a
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.

jo**********************@yahoo.es (jose luis fernandez diaz) wrote in message news:<c2**************************@posting.google. 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.

Jul 22 '05 #5

P: n/a
jo**********************@yahoo.es (jose luis fernandez diaz) wrote in message news:<c2**************************@posting.google. 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
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.