Is it possible to include .cpps? There are integer data types in my main.cpp I want to use in another .cpp, how would I do this?
Printable View
Is it possible to include .cpps? There are integer data types in my main.cpp I want to use in another .cpp, how would I do this?
Yes, it's possible, but it's not good practice to include .cpp files. You should have it in a .h file instead. Just do:Code:#include "file.cpp"
// Or
#include "file.h"
How do I put it in a .h file?
If you want to do an .h-file it's only to open a new file and write:
save it later as an .h-file.Code:#ifndef _name_h_
#define _name_h_
#include <iostream>
.....
using namespace std;
code.......
.
.
.
#endif
If you want your variables to be global, then you have to declare them to be that, else they'll be local variables in your main.cpp-file.
good luck!
AAAHH
NEVER include cpp or c files! NEVER NEVER NEVER!
A header file is simply a file where type, variable and function declarations are. You include the header in every module (.c or .cpp file) where you need the types/functions/variables. NOT vice versa!