-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_namespaces.cpp
More file actions
31 lines (24 loc) · 829 Bytes
/
Copy pathinline_namespaces.cpp
File metadata and controls
31 lines (24 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
namespace SOMETHINGS{
namespace V1{
void doSomething();
}
inline namespace V2{ //inline make the namespace content automatically available throgh the parent namespace, so you don't have to do SOMETHINGS::V2::doSomething(); you
// can just do doSomething(); or SOMETHINGS::doSomething();
void doSomething();
}
}
int main(){
// SOMETHINGS::V1::doSomething();
// SOMETHINGS::doSomething(); // this will resolve to SOMETHINGS::V2::doSomething();
// doSomething(); // this one will resolve to SOMETHINGS::V2::doSomething();
std::cout << "Enter a positive number: ";
int num{};
std::cin >> num;
if (num < 0){
std::cout << "Negative number entered. Making positive.\n";
num = -num;
}
std::cout << "You entered: " << num;
return 0;
}