Currently,I am learning C++ and I observed that objects like vectors,lists can be used if we include their respective header file and std::object_name.Where these classes are actually defined,in their respective header files or in std namespace?
Asked
Active
Viewed 52 times
-2
-
*" header files or in std namespace"* It is not exclusive. you can have namespace split across several files. – Jarod42 Mar 02 '17 at 21:31
-
"namespace" and "include file" are orthogonal. Each include file can have any namespace inside, or no namespace, or multiple namespaces. – Mar 02 '17 at 21:31
-
where is std namespace defined? – yondu_udanta Mar 02 '17 at 21:33
-
Please check this page http://en.cppreference.com/w/cpp/container – ThomasMcLeod Mar 02 '17 at 22:07
1 Answers
2
The namespace std
is slit over many files, and not all defined in one place. Unlike a class, a namespace can be reopened and have new declarations added.
For example, the templates like std::vector
are both declared and defined in their respective headers, because Why can templates only be defined in the header file?.
Other members of namespace std
can be declared in a header, and defined in a cpp file. That cpp file is probably already compiled into a runtime library that your program links to.

Community
- 1
- 1

Bo Persson
- 90,663
- 31
- 146
- 203