3 Replies - 4992 Views - Last Post: 03 September 2009 - 07:12 AM Rate Topic: -----

#1 bita  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • 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  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1147
  • View blog
  • Posts: 7,132
  • 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.
Was This Post Helpful? 1
  • +
  • -

#3 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,900
  • Joined: 25-October 06

Re: calling a function in another function

Posted 03 September 2009 - 07:07 AM

View Postbita, 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()
Was This Post Helpful? 1
  • +
  • -

#4 brds  Icon User is offline

  • D.I.C Addict
  • member icon

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

Re: calling a function in another function

Posted 03 September 2009 - 07:12 AM

View Postbita, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1