Problems compiling templates

  • Thread starter jose luis fernandez diaz
  • Start date
J

jose luis fernandez diaz

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.
 
L

Leor Zolman

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
 
J

Jeff Flinn

jose luis fernandez diaz said:
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
 
L

Leor Zolman

jose luis fernandez diaz said:
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
 
J

jose luis fernandez diaz

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.

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.
 
D

Dave Moore

Hi,

I have found the solution on Intenet:



I hope that this be useful for other people.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top