C++ Zugriff auf Globale Variablen/Objekte in einem namespace mit einer variable/Objekt mit dem gleichen Namen

#include <iostream>
#include <string>
using namespace std;

string a;

namespace myNamespace
{
    string a;
    void output()
    {
        cout << a << endl;
    }
}

int main()
{
    a = "Namespaces, meh.";
    myNamespace::a = "Namespaces are great!";
    myNamespace::output();
}

Das Ergebnis ist "Namespaces sind toll!". So ist es eine Möglichkeit, den Zugriff auf die Globale string einen innerhalb des Namespaces myNamespace, anstatt nur eine lokale?

InformationsquelleAutor Whovian | 2012-05-06
Schreibe einen Kommentar