mirror of https://github.com/CppCon/CppCon2014.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
695 B
C++
26 lines
695 B
C++
#include <iostream>
|
|
|
|
int main() // Part I: Legal, or compile error?
|
|
{ // LEGAL!
|
|
using namespace std;
|
|
|
|
cout << "hello, cruel world!" << endl; // usual "cout"
|
|
|
|
int cout; // this cout HIDES the one at namespace scope
|
|
cout = 10; // uses the int
|
|
std::cout << "cout = " << cout << endl; // 2nd cout is the int
|
|
std::cout << "cout << 5 = " << (cout << 5) << endl; // 2nd cout is int
|
|
}
|
|
|
|
|
|
// Part II: What if we replaced
|
|
// using namespace std;
|
|
// with:
|
|
// using std::cout;
|
|
// using std::endl;
|
|
//
|
|
// ?
|
|
|
|
// Answer: ILLEGAL! A using DECLARATION brings the name into THIS scope,
|
|
// so you can't have a redeclaration in the same scope.
|