What does this mean? Can I get some help please?

Pages: 123
Awesome man I understand it now thank you very much ;D
also one last question lol

Would this be allowed?

1
2
3
4
5
6
7
template<class T1, class T2>
decltype(v1[0]*v2[0]) f(T1 v1[], T2 v2[], size_t count) // Will not compile!
{
decltype(v1[0]*v2[0]) sum(0);
for(size_t i = 0; i<count; i++) sum += v1[i]*v2[i];
return sum;
}
2
3
decltype(v1[0]*v2[0]) f(T1 v1[], T2 v2[], size_t count) // Will not compile!
auto f(T1 v1[], T2 v2[], size_t count) -> decltype(v1[0]*v2[0]) //Should compile! 
Last edited on
but it did compile for me lol. It didnt give any error at compile time, will it at runtime?
If your compiler knows about parameters before it has parsed them, it is a magical unicorn and you should feed it daily. In other words, it's non-standard and you got lucky, and you shouldn't rely on it because it won't work for everyone else.
but it is visual studio 2012... o.O Ultimate
Also i am not calling it. its just there. Maybe that's why?
Ah yes - if you never use a template, the compiler never plugs in the types to it. Templates are literally "templates" - you tell the compiler what types you want it to work with and it uses the definition as a template to generate a function that works with those types. Thus, obviously, not asking the baker to make brown cookies means the baker doesn't make brown cookies, which also means the baker never finds out you spilled all his brown coloring.
Last edited on
I tried calling it and i got a bunch of errors lol.

Ok thankyou.
1>c:\users\anmol\documents\visual studio 2012\projects\tests\tests\tests.cpp(14): error C2784: ''unknown-type' f(T1 [],T2 [],size_t)' : could not deduce template argument for 'T1 []' from 'int'


Is this the correct error?
Why are you passing an int when it needs a pointer? ;)
oh ok ty let me try that lol
ok I have no idea how to do this. can you post an example. Sorry if your annoyed. Im a real big noob lol
This is with the error:
http://liveworkspace.org/code/49gSFG$0
This is without the error:
http://liveworkspace.org/code/49gSFG$1
This shows that unsigned long long + long double = long double:
http://liveworkspace.org/code/49gSFG$4
It says its not published
Whoops, sorry - I didn't realize it worked that way. Try again.
ok ty
Ty but can you do one more except with

1
2
3
4
5
6
7
template<class T1, class T2>
decltype(v1[0]*v2[0]) f(T1 v1[], T2 v2[], size_t count) // Will not compile!
{
decltype(v1[0]*v2[0]) sum(0);
for(size_t i = 0; i<count; i++) sum += v1[i]*v2[i];
return sum;
}
This is with the error:
http://liveworkspace.org/code/NueyI$0
This is without the error:
http://liveworkspace.org/code/NueyI$1
Pages: 123