Q.6) a) What is name conflict problem? How can it be solved using namespaces?
Ans.Suppose that your program have a function name myFunction() and the same function name is also available in standard library. It will create name ambiguity problem because both names would be stored in the global namespace. Name conflict or name ambiguity problem will create wwhen two or more third-party libraries were used by the same program. Another case may be that your class name and third party or predefinedclass name are same, it will create name conflict problem.
Namespace has solved these types of name conflict problem. A namespace allows the same name to be used in different contexts without name conflicts arising.
b) Explain three different types of containers.
Ans.There are three key components of STL and they work in conjunction with other to provide different programming solution
-Containers
-Algorithms
-Iterators
Containers: These are objects that contain other objects. They are implemented as class templates.
Following are some important exaample of container.
Stack, queue, map, multimap, vector, list
AlgorithmsAlgorithms works on container classes. Algorithms provide collection of template functions and mainly used on ranges of elements. The sequence of elements can be accessed through iterators or pointers. There are huge numbers of function available in this header.
Some important functions in < Algorithms > are as follows:
-count
-count_if
-search
-remove
-copy
-sort
IteratorsIterators are used to access the element same as a pointer to cycle through an array.
There are five different types of iterators within STL:
-Input iterators
-Output iterators
-Forward iterators
-Bidirectional iterators
-Random access iterators