I though this was suppose to result as a function which I would call like t(), but I get this error: 't' dose not name a type. So how do I assign a type to it?
Apparently wxdev dose not think either is ok.
And I got a virus and had to delete whole C: I now installed cb, but it has some compiler, something is not linked idk what, I'll ask my friend when he gets on skype, so I can't use that.
This is what I'm trying
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main()
{
int i = 3;
int u = 0;
int r = 60;
auto t = [&](){return r - (i * u);};
while (t() >= 0)
{
cout << t() << endl << u++ << endl;
}
}
@ zoran: If you're using C::B, then you're probably using gcc as the compiler. Make sure you enable the -c++11 compiler switch (look around in the compiler/project settings pages in C::B).
I don't have C::B installed here so I can't check for myself, but a quick bit of googling suggests it is in the "Project Build Options|Compiler Settings tab from within Code::Blocks."
And how dose the computer know what is going to be the return type for this function?
It can do it automatically, but only for small, simple functions by examining the return statement and seeing what the returned expression evaluates to.
For more complex functions (or if you want to), you can explicitly give the return type: