# calling a function in another function

Page 1 of 1

## 3 Replies - 24912 Views - Last Post: 03 September 2009 - 07:12 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=123735&amp;s=f5d4bddf6e37431d58f6c70231db790f&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 bita

Reputation: 3
• Posts: 190
• Joined: 21-April 09

# calling a function in another function

Posted 03 September 2009 - 06:51 AM

Hi guys

my question is about calling a function in another function,is it wrong?

for example below I've defined a function and in it i called 'findFile' function,it works but i want to know is it basically right or i shouldn't call it in another function?

```void employment::deleteRecord(std::vector<string>&lines2 ,string id3)
{

//...

findFile(lines2 , id4);//<HERE IS THE FUNCTION THAT I'VE CALLED IT

//...
}

```

Thanx
Bita

This post has been edited by bita: 03 September 2009 - 06:52 AM

Is This A Good Question/Topic? 0

## Replies To: calling a function in another function

### #2 BetaWar

• #include "soul.h"

Reputation: 1423
• Posts: 8,045
• Joined: 07-September 06

## Re: calling a function in another function

Posted 03 September 2009 - 07:05 AM

Sub routines are a huge part of C/C++. I believe the commonly accepted thought is that if a function starts to get much more than 30 lines of code long you should create sub-functions to decrease that length. Now there are some cases where creating sub-functions really doesn't make sense, but for the most part it is a good idea to use them (it makes the code easier to read - especially if you name the functions nicely, and helps reduce the overall program length - if a function is called multiple times then it saves space in comparison to putting the code inline at all those places).

Hope that makes sense.

### #3 horace

• D.I.C Lover

Reputation: 764
• Posts: 3,804
• Joined: 25-October 06

## Re: calling a function in another function

Posted 03 September 2009 - 07:07 AM

bita, on 3 Sep, 2009 - 12:51 PM, said:

Hi guys

my question is about calling a function in another function,is it wrong?

for example below I've defined a function and in it i called 'findFile' function,it works but i want to know is it basically right or i shouldn't call it in another function?

```void employment::deleteRecord(std::vector<string>&lines2 ,string id3)
{

//...

findFile(lines2 , id4);//<HERE IS THE FUNCTION THAT I'VE CALLED IT

//...
}

```

Thanx
Bita

functions are there to be called, main() is a function so you start calling functions from it
so long as you have a function prototype or function definition for findFile() you can call it from employment::deleteRecord()

### #4 brds

Reputation: 76
• Posts: 515
• Joined: 22-October 08

## Re: calling a function in another function

Posted 03 September 2009 - 07:12 AM

bita, on 3 Sep, 2009 - 07:51 AM, said:

my question is about calling a function in another function,is it wrong?

for example below I've defined a function and in it i called 'findFile' function,it works but i want to know is it basically right or i shouldn't call it in another function?

Is it wrong? No, its kinda the basis of nice maintainable code.
Is it right for what you are trying to accomplish? I don't know, because I don't know what you are trying to do.