Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C/C++ question - Function prototype in other function

C/C++ question - Function prototype in other function

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++helpjson
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adeel Chaudhry
    wrote on last edited by
    #1

    Hello, Pardon me, its a pure question of C/C++ not specific to Visual C++. Can anybody explain what is the purpose of following code: void Function1(int a, int b) { void Function2(int c, int d, int e); // in some header file void Function3(int c, int d, int e); // in some header file int i, k, l; //rest of the code in which Function2 and Function3 are being used! } I have no idea why "Function2" & "Function3" prototypes are defined in the function named "Function1", and is it possible? If yes whats the logic behind it? Any help is highly appreciated. Regards, Adeel

    Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

    N 1 Reply Last reply
    0
    • A Adeel Chaudhry

      Hello, Pardon me, its a pure question of C/C++ not specific to Visual C++. Can anybody explain what is the purpose of following code: void Function1(int a, int b) { void Function2(int c, int d, int e); // in some header file void Function3(int c, int d, int e); // in some header file int i, k, l; //rest of the code in which Function2 and Function3 are being used! } I have no idea why "Function2" & "Function3" prototypes are defined in the function named "Function1", and is it possible? If yes whats the logic behind it? Any help is highly appreciated. Regards, Adeel

      Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      This is just a function declaration. Its purpose is to tell the compiler that in some other place( may be in another file or in the same file ) we have a function defined with name Function2 and Function3 with following prototype. Other wise the compiler will thow compilation error saying the Function2 and Function3 cannot be found.

      nave [OpenedFileFinder] [My Blog]

      A 1 Reply Last reply
      0
      • N Naveen

        This is just a function declaration. Its purpose is to tell the compiler that in some other place( may be in another file or in the same file ) we have a function defined with name Function2 and Function3 with following prototype. Other wise the compiler will thow compilation error saying the Function2 and Function3 cannot be found.

        nave [OpenedFileFinder] [My Blog]

        A Offline
        A Offline
        Adeel Chaudhry
        wrote on last edited by
        #3

        That means, logically it is equal to: void Function2(int c, int d, int e); void Function3(int c, int d, int e); void Function1(int a, int b) { //actual code } Right? Regards, Adeel

        Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

        N 1 Reply Last reply
        0
        • A Adeel Chaudhry

          That means, logically it is equal to: void Function2(int c, int d, int e); void Function3(int c, int d, int e); void Function1(int a, int b) { //actual code } Right? Regards, Adeel

          Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.

          N Offline
          N Offline
          Naveen
          wrote on last edited by
          #4

          Ya almost. But the difference is that, now all the functions after the Function1 will be aware of the Function2 and Function3. If the declation was inside the Function1, only Function1 will be aware of the Function2 and Function3. Trying to call those functions from any other function will create compilation error. That is the scope of the declaration is restricted to the body of Function1.

          nave [OpenedFileFinder] [My Blog]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups