Jump to content

  • Log In with Google      Sign In   
  • Create Account

Multiple File Inclusion


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 07 February 2002 - 03:51 PM

I understand that you can include self-made header files in projects, but what if you had multiple source files? How would you include files that don''t end in .h to your main source file? Also, what kind of things should go in header files and source files? Thanks a lot.

Sponsor:

#2 EvilCrap   Members   -  Reputation: 134

Like
Likes
Like

Posted 07 February 2002 - 06:04 PM

why would you want to include files that dont end in .h or .c/pp to ur main source file?

a header file is used to put definitions in and stuff that you may want to use in other .cpp files.

a .cpp file is an implementation file... you write actual code in it, in general, you can think of a .cpp as program space, while a .h is compiler space.

      
//stdafx.h

#ifndef _stdafx_
#define _stdafx_

#include <iostream>

using namespace std;

char getKey();
void drawStuff();
#endif


//main.cpp

#include "stdafx.h" //allow access to stuff in stdafx.h


void main()
{
getKey();
drawStuff();
}


//stdafx.cpp

#include "stdafx.h"

char getKey() {}
void drawStuff() {}


in general, you can use a headerfile to define class interfaces, 'library' functions, defines/macros, and constants/enums.

Edited by - evilcrap on February 8, 2002 1:06:43 AM

#3 pizza box   Members   -  Reputation: 168

Like
Likes
Like

Posted 08 February 2002 - 07:36 AM

What I am asking is if I can write anything that you would normally put in a .cpp file ( excluding main() ), in a .h file. Are there any things that you can't or shouldn't put in a .h file? Thanks

Woops, sorry I missed that last part you wrote. Thanks for the help.

Edited by - Sethius on February 8, 2002 2:37:59 PM

#4 TobiasS   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 February 2002 - 09:41 AM

As far as i know, the compiler doesn''t differentiate between .cpp and .h files. You should in general put the program code in the .cpp files and all the classes, functions that will be used in more than one .cpp file, definitions and stuff like that in the .h files.

Hope that helped

#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 12 February 2002 - 05:35 PM

The .h files are the interface for you .cpp files, so you include the .h files, and be sure that your make file or Visual C++ project includes the cpp files. The compiler will build each file one at a time, and then the Linker will ensure that it is all there.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS