The C++ namespace: the explicit access, namespace within a class C++ code sample


Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using the namespace within the C++ class, accessing the member explicitly

To show: How to access explicitly using the namespace within the C++ class




// explicit access, namespace within the C++ class

#include <iostream>

using namespace std;


class One



void funct1(char chs)

{cout<<"character = "<<chs<<endl;}



class Two:public One



// the using directive is not allowed in class using namespace One;

void funct1(char *str)

{cout<<"String = "<<str<<endl;}


// using declaration is OK in class

using One::funct1; // overload Two::funct1()



int main(void)


Two Sample;


// calling One::funct1()


// calling Two::funct1()

Sample.funct1("This is string");


return 0;



Output example:


character = P

String = This is string

Press any key to continue . . .



C and C++ Programming Resources | C & C++ Code Example Index