problems about aCC

G

guojianlee

I have some problem ,when compiling program in
hp 11.1
aCC: HP ANSI C++ B3910B A.03.37
,just like this "aCC test.cpp".
but when i compile it with option -AA ,every thing is OK.
source code and error info as follow.who can tell me why ,thank you
very much.

source code:

$vi test.cpp

#include <map>
#include <string>

namespace std {} using namespace std;
int main()
{
map<string,string > m;
string a("11"),b("2222");
m.insert(make_pair(a,b));
}
~
~
error info:

$aCC test.cpp
Error 226: "test.cpp", line 9 # No appropriate function found for call
of 'insert'. Last viable candidate was

"pair<rb_tree<basic_string<char,string_char_traits<char>,allocator>,pair<const

basic_string said:
>,select1st<pair<const

basic_string said:
>,basic_string<char,string_char_traits<char>,allocator>
,less<basic_string<char,string_char_traits<char>,allocator>
>,allocator>::iterator,bool>

map said:
,allocator>::insert(const pair<const

basic_string said:
["/opt/aCC/include/map", line 254]. Argument of type 'struct

pair said:
' could not
be converted to 'const pair<const

basic_string said:
m.insert(make_pair(a,b));
^^^^^^
aCC -AA test.cpp

when I checked /opt/aCC/include/map ,found a macro
"RWSTD_NO_CONST_INST". Maybe it is helpful for you .

class map
{
public:
//
// types
//
typedef Key key_type;
#ifndef RWSTD_NO_CONST_INST
typedef pair<const Key, T> value_type;
#else
typedef pair<Key, T> value_type;
#endif
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef T mapped_type;
 
A

Alf P. Steinbach

* guojianlee:
I have some problem ,when compiling program in
hp 11.1
aCC: HP ANSI C++ B3910B A.03.37
,just like this "aCC test.cpp".
but when i compile it with option -AA ,every thing is OK.
source code and error info as follow.who can tell me why ,thank you
very much.

source code:

$vi test.cpp

#include <map>
#include <string>

namespace std {}

You don't need that, it serves no useful purpose.

using namespace std;

Consider placing this directive inside the function where it's needed.

int main()
{
map<string,string > m;
string a("11"),b("2222");
m.insert(make_pair(a,b));

You haven't included <utility> and so you're not guaranteed to have a
definition of make_pair.



Cheers, & hth.,

- Alf
 
J

James Kanze

I have some problem ,when compiling program in
hp 11.1
aCC: HP ANSI C++ B3910B A.03.37
,just like this "aCC test.cpp".
but when i compile it with option -AA ,every thing is OK.
source code and error info as follow.who can tell me why ,thank you
very much.
source code:
$vi test.cpp
#include <map>
#include <string>

namespace std {} using namespace std;
int main()
{
map<string,string > m;
string a("11"),b("2222");
m.insert(make_pair(a,b));}
error info:

Just a guess, but it looks from the error messages as if the
version of the library you are using isn't completely up to
date. make_pair, in your case, will return an
std::pair< std::string, std::string >. The type needed for
std::map::insert (here) is an std::pair< std::string const,
std::string >. In the standard, there's an implicit conversion
of what you have to what you need, but IIRC, it was added very,
very late in the standardization proceedure, and it's entirely
possible that older libraries don't support it.

My own practice, in such cases, is to typedef the map, and then
use something like:
m.insert( Map::value_type( a, b ) ) ;
This ensures a correct type.

You might, however, want to upgrade to a more recent version of
the library (which probably means upgrading your compiler).

(As Alf points out, you should also probably include <utility>,
to be formally correct, although as <map> uses std::pair, it's
hard to imagine it not including <utility>.)
 
P

Pete Becker

You don't need that, it serves no useful purpose.

It probably isn't needed, but the (sometimes) useful purpose it serves
is to make the using directive that follows it legal when the preceding
headers don't put the library in the namespace std.
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top