Operating System - HP-UX
1832994 Members
2710 Online
110048 Solutions
New Discussion

using "std" as an explicit namespace qualifier

 
SOLVED
Go to solution
Ed Daraki_2
Occasional Advisor

using "std" as an explicit namespace qualifier

I using aCC A.03.25 on a HP-UX B.11.00 and I am having problem using "std" as an explicit namespace qualifier.

The following code is a small test case that shows the problem:

// test.cpp
#include
int main () {
std::cout << "Hello world\n";
return 0;
}

$ aCC -o test test.cpp
Error 24: "test.cpp", line 4 # ':' expected instead of '::'.
std::cout << "Hello world\n";
^^
Warning 612: "test.cpp", line 4 # Label 'std' has no uses.
std::cout << "Hello world\n";
^^^^^

Any ideas?

7 REPLIES 7
Steven Gillard_2
Honored Contributor

Re: using "std" as an explicit namespace qualifier

The .h C++ header files have been deprecated in ANSI C++ and are provided for backwards compatibility only. If you wish to explicitely specify the std namespace, you should include instead of . Eg:

// test.cpp
#include
int main () {
std::cout << "Hello world\n";
return 0;
}

If you've got Stroustrup's latest edition of 'The C++ Programming Language', have a read of section B.3.1 which talks about this change.

Regards,
Steve
harry d brown jr
Honored Contributor

Re: using "std" as an explicit namespace qualifier

// test.cpp
#include
int main () {
cout << "Hello world\n";
return 0;
}

change std::out to cout

live free or die
harry
Live Free or Die
Ed Daraki_2
Occasional Advisor

Re: using "std" as an explicit namespace qualifier

Thanks Steve and Harry for quick replies!

I tried but could not be found.
I searched /usr/include and /opt/aCC/include but didn't find it.

I have to keep the code the way it is because it is shared among several platforms.

Any ideas where is might be?

Thanks in advance for any help!
Steven Gillard_2
Honored Contributor
Solution

Re: using "std" as an explicit namespace qualifier

Thats probably because you're running an old version of the compiler. Update it off a more recent set of application CD's - the latest version is A.03.33 on the Dec 2001 CD's (patchable to A.03.34) See the following web site for more information:

http://h21007.www2.hp.com/dspp/tech/tech_TechSoftwareDetailPage_IDX/1,1703,1743,00.html#11

I don't have access to a system with aCC on it at present but a few months ago we were running A.03.30 and it definitely had the new std namespace aware iostream header file.

Regards,
Steve
Olav Baadsvik
Esteemed Contributor

Re: using "std" as an explicit namespace qualifier


Hi,

If you want to use you will
have to use the option -AA to the compiler.
When using #include your code
may also be changed to this:

#include
using namespace std;
int main () {
cout << "Hello world\n";
return 0;
}

Regards
Olav

Ed Daraki_2
Occasional Advisor

Re: using "std" as an explicit namespace qualifier

Hi Olav,

As I understand the -AA option is not available for aCC A.03.25, so probably as Steve pointed out I have to upgrade my compiler before trying anything.

Because the actual code is shared I have to keep the changes at a minimum to have a lower impact on other platforms that use the same code. That's why I prefer to keep the "std::" qualifier. Is there anything in the new standard that says I should not use it? Why?

Ed

Steven Gillard_2
Honored Contributor

Re: using "std" as an explicit namespace qualifier

No, you're quite correct to use it. In order to avoid using it you need to specify 'using namespace std;' in all your source files (although some compilers do this automatically - can't remember whether aCC does though).

Regards,
Steve