Skip to content

Commit 2f507e7

Browse files
authored
Readed all document and fixed minor errors
1 parent 33a206a commit 2f507e7

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

C++ Syntax.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,9 @@ the other version of this is:
520520
int a = 6, b = 3;
521521

522522
int c = add(a, b);
523-
int c = subtract(a, b);
524-
int c = multiply(a, b);
525-
int c = divide(a, b);
523+
int d = subtract(a, b);
524+
int e = multiply(a, b);
525+
int f = divide(a, b);
526526
```
527527
Which do you like better? First version is more intuitive as for me. The same logic stands behind `operator`s in c++. One of the mottos in c++ is "Create your classes to function as harmoniously as the built-in types". So let's create harmonious
528528
class complex with support for basic arithmethic.
@@ -577,7 +577,7 @@ int main()
577577
}
578578
```
579579
Oh, that's good, but what about output, how could we output it?
580-
It turns out that output is an operator too. Remember `std::cout << something` ? That's an right shift operator, but it is used to denote the output, and `std::cout` is just the global instance of class `std::ostream`. So we could just provide this operator for our own class:
580+
It turns out that output is an operator too. Remember `std::cout << something` ? That's a left shift operator, but it is used to denote the output, and `std::cout` is just the global instance of class `std::ostream`. So we could just provide this operator for our own class:
581581
```c++
582582
#include <iostream>
583583
@@ -609,7 +609,7 @@ int main()
609609
std::cout << a / b;
610610
}
611611
```
612-
There are also left shift operator denoting input, recall `std::cin >> something;`. About different kinds of operators, you can read [here](http://en.cppreference.com/w/cpp/language/operators).
612+
There are also right shift operator denoting input, recall `std::cin >> something;`. About different kinds of operators, you can read [here](http://en.cppreference.com/w/cpp/language/operators).
613613

614614
### 1.6 Templates
615615
Let's try to write `add` function from previous item.
@@ -619,7 +619,7 @@ double add(double fst, double snd)
619619
return fst + snd;
620620
}
621621
```
622-
Cool, but this won't work with `int`, and many other types! Templates is a mechanism that allows generalizing of the function, that works with every type that supports `operator+`, here is the notation:
622+
Cool, but this won't work with `int`, and many other types! Templates is a mechanism that allows generalizing of a function, that works with every type that supports `operator+`, here is the notation:
623623
```c++
624624
template <typename T> // T is the name of a type
625625
T add(const T& fst, const T& snd)
@@ -665,7 +665,7 @@ Also the new feature is coming to c++20, named [concepts](https://cppdepend.com/
665665

666666
## 2.0 General C++ Syntax
667667
### 2.1 Namespaces
668-
In big projects, there are thousands of varibles, and each neede it's own name. Let's imagine that there are library with linked list structure, and we need to somehow represent single node of a list:
668+
In big projects, there are thousands of variables, and each needs it's own name. Let's imagine that there are library with linked list structure, and we need to somehow represent single node of a list:
669669
```c++
670670
// file named "LinkedList.h"
671671
template <typename T> // use of templates
@@ -676,7 +676,7 @@ struct Node { // pretty and short name
676676
T data;
677677
};
678678
```
679-
And there library with binary search tree structure:
679+
And there are library with binary search tree structure:
680680
```c++
681681
// file named "BST.h"
682682
template <typename T>
@@ -697,7 +697,7 @@ int main()
697697
Node<int> * a = new Node<int> {nullptr, nullptr, 3}; // oops
698698
};
699699
```
700-
How do compiler know what Node we are about to use? `namespace` comes to rescue:
700+
How do compiler know what Node we are about to use? `namespace` comes to the rescue:
701701
```c++
702702
// "LinkedList.h"
703703
namespace lst {
@@ -728,12 +728,12 @@ int main()
728728
bst::Node<int> * a = new bst::Node<int> {nullptr, nullptr, 3}; // it is bst node
729729
};
730730
```
731-
So now we could specialize, and don't be afraied of name collisions, just use simple, pretty names.
732-
By the way remember `std::cout`? It is object of `namsepaces std`, it is recommended to use full namespace name almost everywhere. But if it is your small(very small) project you could try:
731+
So now you could specialize, and don't be afraid of name collisions, just use simple, pretty names.
732+
By the way remember `std::cout`? It is object of `namsepaces std`, it is recommended to use full namespace names almost everywhere, because you are sure what structure you are using. But if it is your small(very small) project you could try:
733733
```c++
734734
#include <iostream>
735735

736-
using namespace std; // everything inside namespace std, becomes visible
736+
using namespace std; // everything inside namespace std becomes visible
737737

738738
int main()
739739
{

0 commit comments

Comments
 (0)