+ 3
What is the most difficult module in c++?
7 ответов
+ 7
on here or like ever? most people would say pointers i guess
+ 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...
}
+ 3
ooh. thank you.
+ 3
@Norbivar thank you for your opinion. 😊
+ 3
Template metaprogramming can be one of the hardest, maybe just for me...
Trying to understand it , but just unable to till date...
+ 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.
+ 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.