+ 3

What is the most difficult module in c++?

4th Jun 2017, 9:48 AM
primex
primex - avatar
7 ответов
+ 7
on here or like ever? most people would say pointers i guess
4th Jun 2017, 10:03 AM
jay
jay - avatar
+ 5
@Norbivar Im talking about template 'metaprogramming' here... Eg - template<int n> class Factorial //The most interesting, int instead of typename! { public: static const long long result= n*Factorial<n-1>::result; }; template<> class Factorial<0> { public: static const long long result=1; }; main() { cout<<Factorial<5>::result<<endl; //Ever seen <> containing a number? //Shall print 120... }
4th Jun 2017, 3:23 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
ooh. thank you.
4th Jun 2017, 10:03 AM
primex
primex - avatar
+ 3
@Norbivar thank you for your opinion. 😊
4th Jun 2017, 12:35 PM
primex
primex - avatar
+ 3
Template metaprogramming can be one of the hardest, maybe just for me... Trying to understand it , but just unable to till date...
4th Jun 2017, 1:04 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 1
I would not agree. Pointers are easy to handle, all it requires is some common sense and predictive mind. Nothing is too hard, though templatization with specialisations can give hard times.
4th Jun 2017, 12:14 PM
Norbivar
Norbivar - avatar
+ 1
@Kinshuk it is part of it and it actually is quite useful. You could write all of your programs withour it though. You see, declaring templates is essentially telling the compiler that this function/class will and could be used with different types (example would be vectors, stacks, pretty much every STL containeer and algorith). What happens is that compile-time the computer checks which types you used and creates copies of the function/class for the given type (simple as that). This puts you into the ideal situation where you don't need to maintain 4-5-... copies of the same function.
4th Jun 2017, 3:13 PM
Norbivar
Norbivar - avatar