Operating System - OpenVMS
1828492 Members
2721 Online
109978 Solutions
New Discussion

STL example compile errors

 
Bob Williams_5
Occasional Contributor

STL example compile errors

The attached file contains example C++ code that runs fine on an Alpha running Compaq C++ V6.3-020 for OpenVMS Alpha V7.2, but on another machine running Compaq C++ V6.3-020 for OpenVMS Alpha V7.2 I get the following:
"$ cxx stl_set2.cxx

cout << *p;
.........^
%CXX-E-NOMATOPRFUN, no operator "<<" matches these operands
operand types are: ostream_withassign << const state
at line number 62 in file GLORIA$DKA300:[PROGRAM.WILLIAMS_R]STL_SET2.CXX;1

cout << *p;
.........^
%CXX-E-NOMATOPRFUN, no operator "<<" matches these operands
operand types are: ostream_withassign << const state
at line number 72 in file GLORIA$DKA300:[PROGRAM.WILLIAMS_R]STL_SET2.CXX;1

%CXX-I-MESSAGE, 2 errors detected in the compilation of "GLORIA$DKA300:[PROGRAM.WILLIAMS_R]STL_SET2.CXX;1".

anybody got any clues? Thanks.
5 REPLIES 5
John Gillings
Honored Contributor

Re: STL example compile errors

Bob,

This looks completely plausible and reasonable to me. There is no "<<" operator defined for the operand type "state". What are you expecting it to display?

You either need to define the operator, or use an expression that results in a data type for which the "<<" operator is defined.

Why did it "work" before? Maybe a bug that's been fixed? Although I can compile your program under an older version of C++, I can't link it (missing some components?). So, I can't see what output you were getting.
A crucible of informative mistakes
Bob Williams_5
Occasional Contributor

Re: STL example compile errors

John,
The program prints:
Alaska's capital is Juneau.
Arkansas's capital is Little Rock.
California's capital is Sacramento.
Illinois's capital is Springfield.
Missouri's capital is Jefferson City.
Nevada's capital is Carson City.
West Virginia's capital is Charleston.
Wisconsin's capital is Madison.

Looking for Wisconsin.
Found.
Wisconsin's capital is Madison.

It runs OK under Windows and on one Alpha box, but not the one I have to work with. I'm trying to figure out why that is so.
John Gillings
Honored Contributor

Re: STL example compile errors

Bob,

Note that the error message says the operand type is "const state".

If you change the code defining the operator to:

ostream & operator<<(ostream &s, const state &o)

the NOMATOPRFUN error goes away, but you then get a complaint about get_name and get_capital. Removing those references from the operator, I can get your program to compile and run, but obviously I don't see the names.

So, it looks like this is something to do with overly zealous type checking by the compiler, distinuishing between a constant and variable?

I can't see a reason why the compiler would think that *p refers to a constant.

If that doesn't help, please log a case with your local customer support centre.

(personally I subscribe to the school of thought that C++ was a huge joke played on the programmer community by Bjarne Stroustrup)
A crucible of informative mistakes
Bob Williams_5
Occasional Contributor

Re: STL example compile errors

John,
HP support's answer agreed with yours on changing "ostream &operator<<(ostream &s, state &o)" to "ostream &operator<<(ostream &s, const state &o)". Also, I need to change "string get_name() { return name; }" to "string get_name() const { return name; }" and do the same for "string get_capital()".
I've attached their response, where they explain the change in the latest version of C++ and discuss fixes and workarounds.
Bob Williams_5
Occasional Contributor

Re: STL example compile errors

See above.