Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Question about project #include s

Author
Message
Qqite
14
Years of Service
User Offline
Joined: 28th Feb 2010
Location: Florida, U.S.
Posted: 3rd Jan 2012 03:24
So I'm trying to figure out how to get multipage project running.

Atm I am think DBPro and that if I include a file that it just takes that page and "pastes" it in the project main file.

But then my functions didn't work.
So I made a .h file (after reading that need one anyways) and it worked again.

But NOW I'm trying to use a function that was included in main.cpp in the file Loop.cpp. It says that it is not declared.

Once I include the file AGAIN into that page it works...
Also, my global variables/constants don't pass over either.

What gives?

So here are my official two questions:
Does including the same file multiple times waste memory and copy-pastes the code that many times?

Is there any other way to take an imported function to another page?

Ventures of the worlds around us are limited only by our imagination.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 3rd Jan 2012 12:53 Edited at: 3rd Jan 2012 12:56
Quote: "Does including the same file multiple times waste memory and copy-pastes the code that many times?"


No, in C++ it doesn't waste anything, because by including your .h header files, you just pass in the declaration of your functions (you can think of a memory address where the actual function code is stored just once). The code of the function is usually implemented in some .cpp file.
There may be a lot more to explain about it, but a more easy explanation is this: With you're header files you just tell all your other files (that include this header) the name of the functions (and other stuff), the actual code that's behind these function names is then written in some other code file.

Here is an example:

-> MyMathFunctions.h



-> MyMathFunctions.cpp



You can then just include the header file in your program files to use these functions. The compiler will then look up the functions code in the code file.

Note: You could also split the code implementation into multiple files which is handy for larger functions or classes. As an example here are the functions from the same header as above split into multiple files:

-> MyMathFunctionsAdd.cpp



-> MyMathFunctionsMultiply.cpp



I hope this makes some sense and that it helps you a bit.

Login to post a reply

Server time is: 2024-11-19 05:37:32
Your offset time is: 2024-11-19 05:37:32