Seperate files?

I want to put my functions in seperate files but i dont know what it goes in, do i put it in a blank file, file, custom file? what extension can it have? is there a certain one? can i just name it any extension?
Hello,

file A.cpp (where you use the function).
1
2
3
4
5
6
7
8
9
#include "MyFunctions.h"

using namespace std;

int main() {
    ...
    mySampleFunction();
    return 0;
}


File Myfunctions.h
1
2
3
4
5
6
#ifndef __MyFunctions__
#define __MyFunctions__

void mySampleFunction();

#endif 


File MyFunctions.cpp
1
2
3
4
5
6
7
8
9
10
#include "MyFunctions.h"
#include <iostream>

using namespace std;

void mySampleFunction() {
    int i=0;
    i++;
    cout << "i=" << i << endl;
}


with g++ compiler, you just run: g++ A.cpp MyFunctions.cpp A

Hope it answers your question.
Topic archived. No new replies allowed.