lecture-19a - C+ NAMESPACES NAMESPACES Recent addition to...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ NAMESPACES
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming C++ Namespaces R.B. Lenin Winter 2006 DA-IICT 2 NAMESPACES z Recent addition to C++ z Purpose { localize the names of identifiers to avoid name collisions { localizes the visibility of names declared within it { anything defined within a namespace statement is within the scope of that namespace z Syntax: namespace name { // declarations }
Background image of page 2
Object Oriented Programming C++ Namespaces R.B. Lenin Winter 2006 DA-IICT 3 NAMESPACES namespace MyNameSpace { int i, k; void myfunc(int j) { cout << j; } class myClass { public: void seti(int x) { i = x } int geti() { return i; } }; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Object Oriented Programming C++ Namespaces R.B. Lenin Winter 2006 DA-IICT 4 NAMESPACES z Scope { Identifiers defined within a namespace can be referred to directly within that namespace z member function geti uses i directly { From outside the namespace: MyNameSpace::i = 10; { Declaring an object of type myClass MyNameSpace::myClass ob;
Background image of page 4
Object Oriented Programming C++ Namespaces
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

lecture-19a - C+ NAMESPACES NAMESPACES Recent addition to...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online