I am not sure why compiler throws error here? the issue here is my TestLoop class implementation doesn't even work. There is some functionality issue apart from this compiler error. But I am not able to figure it out.
main.cpp:22:15: error: no member named 'fourth' in 'std::pair<const std::shared_ptr<TestLoop::Arguments>, int>'
return itr->fourth;
~~~~~^
1 error generated.
main.cpp:22:15: error: no member named 'fourth' in 'std::pair<const std::shared_ptr<TestLoop::Arguments>, int>'
You essentially have code:
1 2 3 4 5
std::unordered_map<std::shared_ptr<Arguments>, int> calcs;
auto itr = calcs.find(arg);
if (itr != calcs.end())
returnitr->fourth; // error
The calcs is unordered_map.
Therefore, the itr is a interator to map, because that is what the map::find() returns.
An element of map, is a pair and that the iterator points to.
The compiler points out that a pair (std::pair<const std::shared_ptr<TestLoop::Arguments>, int>) does not have member "fourth".
That is a clear error. You can't tell whether there are any "functionality issues" as long as you can't even compile the program.
The first in that pair is a const std::shared_ptr<TestLoop::Arguments>
The second in that pair is an int
The pair does not have fourth.
making a math function (mod) is just a mess and I recommend against it.
- it bloats your math expressions, harder to read for large expressions
- it redefines a basic operator to do the same thing it already did for no reason
- disrupts normal readability both for the whole expression and also around operator precedence for other coders
- if the compiler can't inline due to flags or internal logic, it may bork performance
this looks like things people do when they come from another language and do not want to learn the new language, they want it to look like what they already know. C++ gives you a lot of tools to make this happen, but you should try to avoid the temptation as the result is always worse in one way or another than doing it in c++ directly.
Edit -- sorry, had the C low level stuff on my mind, brain fail.