[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Re: [NOVICE] C++



> > Nu vi er ved det, er det heller ikke særlig god prgrammeringsskik
> > (eller i overensstemmelse ISO'en) at dumpe iostream-klasen i globalt
> > navnerum med <iostream.h>. :)
> 
> Forklar lige nærmere , og hvis hvordan du vil gøre det.

Standarden formaliserer begrebet navnerum (namespace) som en metode
til at gruppere beslægtede deklarationer i samme (u)navngivne scope.
Ifølge standarden er elementer i i standard c++ biblioteket defineret
i navnerummet std (namespace std). Med #include<iostream.h> deklarerer
man iostream-klassen i det globale navnerum, hvilket "forurener" det.
Pointen er at holde indholdet af std, elementerne i stdlib, i et scope
for sig fra programmets globale scope. 
For at tilgå std må man ifølge standarden enten:

1) deklarere hele std i det globale navnerum:

#include<iostream> 

using namespace std;

int main(void)
{
cout << "Test\n";
return 0;
} 

Det er selvfølgelig ikke nogen særlig elegant metode,
eftersom det ødelægger hele pointen med navnerummet std.

2) bruge scope-operatoren til at tilgå std

#include<iostream> 

int main(void)
{
std::cout << "Test\n";
return 0;
} 

3) deklarere specifikke objekter fra std i det globale
navnerum

#include<iostream> 

using std::cout;

int main(void)
{
cout << "Test\n";
return 0;
}

 
-- 
Mvh
Lau Sennels


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *