Void Functions and Running Functions Simalteniously

Hi all,

I was wondering how to make a predefined void function in C++. I can make int functions using this message and I've looked around for tutorials. It seems that I have done everything correctly, but my standard code::blocks complier keeps giving me errors.
I have typed the following at the top of my main.cpp file:
 
#include "header.h" 

I have typed the following inside my header.h file:
 
void function();

And I have made a file called function.cpp and typed this at the top:
1
2
3
4
5
#include "header.h"

void function(){
     // blah blah blah
}

Could you tell me what I've done wrong?

Also I was wondering if I could make 2 or 3 functions work siminutenliously at dikfferent parts of the screen.
For example, could I make a timer or something put that at the top of the screen and a void function in the center part of the screen and make them work at the same time?

Thanks for the help guys!
Last edited on
My psychic sense is not working well today. Tell us the errors.
It says that the function, function() has not been defined or something like that
I suspect you're not compiling function.cpp
Last edited on
I just tried that by building my entire workspace and it still comes up with the same error.
Oh wait sorry, I just tried to compile the file, yet it says it isn't asssigned to any target
Last edited on
Did you include header.h in the cpp file where you are trying to use function()?

As for simultaneous execution of functions, that's a complex topic called multi-threading, where you start other threads from functions. The way to do it is platform dependent, and there are some libraries that greatly simplify it, but overall multithreading is much harder than any other aspect of C++, and it is difficult to get right. I suggest some Googling if you're up to the task...
The following works fine:

main.cpp
1
2
3
4
5
6
7
#include "header.h"

int main()
{
function();
return 0;
}


header.h
void function();

function.cpp
1
2
3
4
5
#include "header.h"
#include <iostream>
void function(){
std::cout << "Using function";
}



Build command
g++ main.cpp function.cpp


Output
Using function
Last edited on
Thanks L B, and I did include it in the main(), which is where I am using it.
You need to link with it. It'll be one of your IDE settings.
Topic archived. No new replies allowed.