For example, I got the main.cpp , when the main() is finish i want to call the joke.cpp how do i do that?
Use header files..Buddy
you can make your functions inside your header files, then call them in your main function in main.cpp.
Code:
//joke.h (Header file)
#ifndef JOKE_H
#define JOKE_H
#endif
void someFunction(int someParam); //The full function is stored in joke.cpp
Code:
//main.cpp
#include "joke.h"
int main()
{
someFunction(22);
return 0;
}
Posts 1–15 of 16 · Page 1 of 2
Post a Reply
Tags for this Thread
None
Originally Posted by master131
Code:
//joke.h (Header file)
#ifndef JOKE_H
#define JOKE_H
#endif
void someFunction(int someParam); //The full function is stored in joke.cpp
Code:
//main.cpp
#include "joke.h"
int main()
{
someFunction(22);
return 0;
}
Yeah that works, But i still trying to understand for what is others cpp files..why would i add them? Its not like vb or c# that you can make form2.show()...I dont understand it..I can just add new functions on the main.cpp idk..
It might be beccause you want to reuse some other cpp files from a previous project or to stop cluttering 1 file with a whole bunch of code that can be used again.
Originally Posted by -Away
Yeah that works, But i still trying to understand for what is others cpp files..why would i add them? Its not like vb or c# that you can make form2.show()...I dont understand it..I can just add new functions on the main.cpp idk..
Like say you got a whole bunch of Directx shit in your project & a whole bunch of other shit
You dont wanna cluster all that into one cpp file. So ya do this
Like say you got a whole bunch of Directx shit in your project & a whole bunch of other shit
You dont wanna cluster all that into one cpp file. So ya do this
Incorrect. C++ is a multi-paradigm language. Ex: STL is not OOP.
Originally Posted by whit
Code:
extern Directx D3D;
Avoid global state. Instantiate the object within main. If it must be global, use the singleton pattern.
You don't "call a CPP file" - a cpp file only contains function definitions (and their bodies, and variables).
You must call a function inside the CPP file. The easiest way to do this is to use the C header file and declare a function which your CPP file has, and call it O:
Brainfuck.
Originally Posted by Fovea
Improper header guard.
Incorrect. C++ is a multi-paradigm language. Ex: STL is not OOP.
Avoid global state. Instantiate the object within main. If it must be global, use the singleton pattern.
Get off me, I was doing it in a rush.
Code:
//joke.h (Header file)
#ifndef JOKE_H
#define JOKE_H
void someFunction(int someParam); //The full function is stored in joke.cpp
#endif
Better?
Originally Posted by -Away
Yeah that works, But i still trying to understand for what is others cpp files..why would i add them? Its not like vb or c# that you can make form2.show()...I dont understand it..I can just add new functions on the main.cpp idk..