1Class is a blueprint or template which you can create as many objects as you
2like. Object is a member or instance of a class.
3Class is declared using class keyword, Object is created through
4new keyword mainly. A class is a template for objects. A class defines
5object properties including a valid range of values, and a default value.
6A class also describes object behavior.
1.wp-block-code {
2 border: 0;
3 padding: 0;
4}
5
6.wp-block-code > div {
7 overflow: auto;
8}
9
10.shcb-language {
11 border: 0;
12 clip: rect(1px, 1px, 1px, 1px);
13 -webkit-clip-path: inset(50%);
14 clip-path: inset(50%);
15 height: 1px;
16 margin: -1px;
17 overflow: hidden;
18 padding: 0;
19 position: absolute;
20 width: 1px;
21 word-wrap: normal;
22 word-break: normal;
23}
24
25.hljs {
26 box-sizing: border-box;
27}
28
29.hljs.shcb-code-table {
30 display: table;
31 width: 100%;
32}
33
34.hljs.shcb-code-table > .shcb-loc {
35 color: inherit;
36 display: table-row;
37 width: 100%;
38}
39
40.hljs.shcb-code-table .shcb-loc > span {
41 display: table-cell;
42}
43
44.wp-block-code code.hljs:not(.shcb-wrap-lines) {
45 white-space: pre;
46}
47
48.wp-block-code code.hljs.shcb-wrap-lines {
49 white-space: pre-wrap;
50}
51
52.hljs.shcb-line-numbers {
53 border-spacing: 0;
54 counter-reset: line;
55}
56
57.hljs.shcb-line-numbers > .shcb-loc {
58 counter-increment: line;
59}
60
61.hljs.shcb-line-numbers .shcb-loc > span {
62 padding-left: 0.75em;
63}
64
65.hljs.shcb-line-numbers .shcb-loc::before {
66 border-right: 1px solid #ddd;
67 content: counter(line);
68 display: table-cell;
69 padding: 0 0.75em;
70 text-align: right;
71 -webkit-user-select: none;
72 -moz-user-select: none;
73 -ms-user-select: none;
74 user-select: none;
75 white-space: nowrap;
76 width: 1%;
77}function Person(name) {
78 this.name = name;
79}
80
81Person.prototype.getName = function () {
82 return this.name;
83};
84
85var john = new Person("John Doe");
86console.log(john.getName());Code language: JavaScript (javascript)
1/* Any Element With Class Title */
2.title {
3}
4
5/* ? */
6#nav {
7}
8
9/* ? */
10div {
11}
12
13/* ? */
14h2 {
15}
1#include <iostream>
2#include <utility>
3
4template<class T, class U>
5auto add(T t, U u) { return t + u; } // the return type is the type of operator+(T, U)
6
7// perfect forwarding of a function call must use decltype(auto)
8// in case the function it calls returns by reference
9template<class F, class... Args>
10decltype(auto) PerfectForward(F fun, Args&&... args)
11{
12 return fun(std::forward<Args>(args)...);
13}
14
15template<auto n> // C++17 auto parameter declaration
16auto f() -> std::pair<decltype(n), decltype(n)> // auto can't deduce from brace-init-list
17{
18 return {n, n};
19}
20
21int main()
22{
23 auto a = 1 + 2; // type of a is int
24 auto b = add(1, 1.2); // type of b is double
25 static_assert(std::is_same_v<decltype(a), int>);
26 static_assert(std::is_same_v<decltype(b), double>);
27
28 auto c0 = a; // type of c0 is int, holding a copy of a
29 decltype(auto) c1 = a; // type of c1 is int, holding a copy of a
30 decltype(auto) c2 = (a); // type of c2 is int&, an alias of a
31 std::cout << "a, before modification through c2 = " << a << '\n';
32 ++c2;
33 std::cout << "a, after modification through c2 = " << a << '\n';
34
35 auto [v, w] = f<0>(); //structured binding declaration
36
37 auto d = {1, 2}; // OK: type of d is std::initializer_list<int>
38 auto n = {5}; // OK: type of n is std::initializer_list<int>
39// auto e{1, 2}; // Error as of DR n3922, std::initializer_list<int> before
40 auto m{5}; // OK: type of m is int as of DR n3922, initializer_list<int> before
41// decltype(auto) z = { 1, 2 } // Error: {1, 2} is not an expression
42
43 // auto is commonly used for unnamed types such as the types of lambda expressions
44 auto lambda = [](int x) { return x + 3; };
45
46// auto int x; // valid C++98, error as of C++11
47// auto x; // valid C, error in C++
48}