Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Program With C++ style (http://www.go4expert.com/forums/program-cpp-style-t18563/)

sdmahapatra 16Jul2009 14:29

Program With C++ style

Hi all,I have written a program in c++ using visual studio 2008.I've create only one source file and written all the codes including header files within .cpp extension and program is running well.But I want to split this program like

.h extension
be present into the header file and

.cpp extension
into the source files separately (one is for functions and one is for main()) and then want to execute the whole program.
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

xpi0t0s 16Jul2009 15:42

Re: Program With C++ style
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.

sdmahapatra 16Jul2009 16:13

Re: Program With C++ style
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.


xpi0t0s 16Jul2009 18:56

Re: Program With C++ style
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):


#define FOO 27
int bar();


#include <stdio.h>
#include "inc.h"

int main()
  printf("FOO=%d; bar()=%d\n",FOO,bar());
  return 0;


#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

sdmahapatra 16Jul2009 23:13

Re: Program With C++ style
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

All times are GMT +5.5. The time now is 00:42.