You're mostly correct regarding cout and cin. They are objects (rather than functions) specified under the std namespace. The following are their C++ standard declarations:
Header <iostream> synopsis
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
}
The scope resolution operator is denoted by ::.
Because the identifiers cout and cin are declared within std, we must qualify them with std::.
Classes function similarly to namespaces in that the names stated within the class belong to the class.
As an example:
class foo
{
public:
foo();
void bar();
};
The foo function Object() { [native code] } is a member of the foo class.
They share the same name because the function Object() { [native code] } is the same.
The function bar is also a foo member.
Because they are members of foo, we must qualify their names when referring to them outside of the class.
After all, they are members of that group.
So, if you want to declare the function Object() { [native code] } and bar outside of the class, you must do so as follows:
foo::foo()
{
// Implement the constructor
}
void foo::bar()
{
// Implement bar
}
This is due to the fact that they are specified outside of the class.
If you hadn't included the foo:: qualifier to the names, you'd be introducing some new functions in the global scope rather than as foo members.
For example, consider the following:
void bar()
{
// Implement different bar
}
Because it is in a distinct scope, it is permitted to have the same name as the function in the foo class.
This bar is global, whereas the other bar belongs to the foo class.