开发者

How do I call a function inside of another function in C++? [closed]

开发者 https://www.devze.com 2023-03-29 21:03 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andc开发者_StackOverflow中文版annot be reasonably answered in its cu
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and c开发者_StackOverflow中文版annot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

How do I call a function inside of another function in C++?


I don't think this is possible.

I disagree:

void bar()
{
}

void foo()
{
    bar();   // there, I use bar inside foo
}

If you want to use a function that hasn't been defined yet, you must declare it before you can use it:

void baz();   // function declaration

void foo()
{
    baz();
}

void baz()    // function definition
{
}


you can do so by using lambda, new feature on the new standard C++0x

int main()
{
    auto square = [&](int x) { return x*x; };
    auto a = square(3);
    return 0;
}

http://www2.research.att.com/~bs/C++0xFAQ.html#lambda

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号