Im not sure if this is how the process would work, but if i am to say create a header file named myheader and in that header wrote

#define functionName
{
code...
}

and then wrote a .cpp file and in the source code I would #include <myheader> and I called functionName(); somewhere in the source, i would not have to write the code for that function in my source file because it is included in my header correct?

This would also allow for compiling if I called the function before I wrote one if I were to regularly just write the function code in my source?

Sorry if the question is unclear, just ask if your confused =D

thanks

This is absolutely awful. Do not do what you are talking about doing.

Tell us what your problem is, what you really are trying to achieve, instead of asking about one particular mechanical option, so that a better solution can be recommended.

I'm just curious as to how the system works, and i am obviously still a beginner in programming. I'm trying to figure out how to write headers and what exactly they do. I know that they carry pre defined functions correct? So how do i make my own?

Header files typically contain declarations of functions, not their definitions. Typically, the implementations are placed in a similarly named cpp file. Your project will then have multiple cpp files.

Also, #define is not how you declare or define functions; I don't know what you're thinking.

For example, I might want to have a function fooz available by a header file "foo.h". So in foo.h I'll have

#ifndef guard_foo_h_
#define guard_foo_h_

int fooz();

#endif /* guard_foo_h_ */

And in foo.cpp

int fooz() {
    return 4;
}

Then, some other file, like bar.cpp, might #include "foo.h" so that the compiler sees the declaration of fooz. Or the writer of bar.cpp could just manually write

int foo();

to inform the compiler about the declaration.

Then, after you compile foo.cpp and bar.cpp and link them together, you'll get a working program where a function written in bar.cpp calls a function written in foo.cpp.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.