-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperatorAccessElement.cpp
More file actions
52 lines (40 loc) · 921 Bytes
/
OperatorAccessElement.cpp
File metadata and controls
52 lines (40 loc) · 921 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* \file OperatorAccessElement.cpp
* \brief
*
* \todo
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
struct Occurance
{
int count;
// Default Constructor
// Un Comment it to compile the code
Occurance()
{
this->count = 0;
}
// Parametrized constructor
Occurance(int count)
{
this->count = count;
}
};
int main() {
// Map of string & int i.e. words as key & there
// occurrence count as values
std::map<std::string, Occurance> wordMap = {
{ "is", Occurance(6) },
{ "the", Occurance(5) }
};
// As key is not in map, so operator[] will create new entry
// With default value of value field. Therefore, Will compile
// only if Occurance sruct has default constructor.
Occurance occur = wordMap["Hello"];
STD_UNUSED(occur);
for (auto elem : wordMap)
std::cout << elem.first << " :: " << elem.second.count << std::endl;
return 0;
}