FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learnmoderncpp-tutorial/headers/06-pixel1.cpp at main · cpp-tutor/learnmoderncpp-tutorial · GitHub
cpp-tutor
/
learnmoderncpp-tutorial
Public
Notifications
You must be signed in to change notification settings
Fork
24
Star
167
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learnmoderncpp-tutorial
/
headers
/
06-pixel1.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
41 lines (34 loc) · 874 Bytes
Breadcrumbs
learnmoderncpp-tutorial
/
headers
/
06-pixel1.cpp
Copy path
File metadata and controls
41 lines (34 loc) · 874 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
30
31
32
33
34
35
36
37
38
39
40
41
//
06-pixel1.cpp : Color and position Pixel type through composition
#
include
<
iostream
>
#
include
<
string_view
>
using
namespace
std
;
struct
Point
{
int
x{}, y{};
};
enum
class
Color
{ red, green, blue };
struct
Pixel
{
Point pt;
Color col{};
};
string_view
get_color
(Color c) {
switch
(c) {
case
Color::red:
return
"
red
"
;
case
Color::green:
return
"
green
"
;
case
Color::blue:
return
"
blue
"
;
default
:
return
"
<no color>
"
;
}
}
int
main
() {
Pixel p1;
cout <<
"
Pixel p1 has color
"
<<
get_color
(p1.
col
);
cout <<
"
and co-ordinates
"
<< p1.
pt
.
x
;
cout <<
'
,
'
<< p1.
pt
.
y
<<
'
\n
'
;
Pixel p2{ { -
1
,
2
}, Color::blue };
cout <<
"
Pixel p2 has color
"
<<
get_color
(p2.
col
);
cout <<
"
and co-ordinates
"
<< p2.
pt
.
x
;
cout <<
'
,
'
<< p2.
pt
.
y
<<
'
\n
'
;
}
Back
|
FazBrowse Home
|
New Git URL