Program With C++ style

Discussion in 'C++' started by sdmahapatra, Jul 16, 2009.

  1. sdmahapatra

    sdmahapatra New Member

    Joined:
    Jun 16, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    I've tried myself but failed as I never before use visual studio (VC++).So I need your suggestion to solved this problem.Which steps I need to follow?How do I separate the module in proper way?Which portion should I care more?etc....So please give your suggestion to know actual advantages of c++/vc++.


    With warm Regards
    sdmahapatra
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    The point of header files is to share definitions between multiple source files. So if you only have one source file there's no point in having a header file.
     
  3. sdmahapatra

    sdmahapatra New Member

    Joined:
    Jun 16, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for your suggestion, So xpi0t0s, If I don't have one source file then how to do this? header files,class,member functions(for process) and main(for application) should be in separate window and I want to execute the program properly.

    Thanks
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    It doesn't necessarily follow that stuff that has to be in different windows has to be in different source files. Form design and software design are linked but do not necessarily have to follow each other. Anyway here is an example of a header file included by two source files (not tested):

    inc.h:
    Code:
    #define FOO 27
    int bar();
    
    main.c:
    Code:
    #include <stdio.h>
    #include "inc.h"
    
    int main()
    {
      printf("FOO=%d; bar()=%d\n",FOO,bar());
      return 0;
    }
    
    gronk.c:
    Code:
    #include <stdio.h>
    #include "inc.h"
    
    int bar()
    {
      printf("in bar(), returning %d\n",FOO);
      return FOO;
    }
    
    Compile with something like gcc main.c gronk.c -o main
    and this will compile main.c and gronk.c to produce main.o and gronk.o, then link them together.
    Output should be something like:

    in bar(), returning 27
    FOO=27; bar()=27
     
  5. sdmahapatra

    sdmahapatra New Member

    Joined:
    Jun 16, 2009
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Hi xpi0t0s, yes I'll try it and if it'll going well then using this way I'll try to go more depth and then I let you know. thanks xpi0t0s for your concern about this problem.I think it will enough for me.thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice