how to create a .cpp and .h file

Pages: 12
So you just need to create a project with the IDE and they will be linked automatically.
Notice that when you #include a header the sourcecode in the header is placed by the preprocessor in the position of the #include line.
If you get Linker errors (errors starting with 'LNK') you will know that you may have problem with linked source files (eg: missing definitions)
Thanks !
but can i use

#ifndef MYHEADER
#define MYHEADER


#endif


in my .cpp file ??
Last edited on
Yes but is better having it in the header
Thank you Buzzy !!
you have been a great help.
Buzzy you are a great buddy !!
Buzzy? lol After all the help he gave to you, you pronounce his name wrong!? OMG! ROLF :D

It's like "Thank's Jimmy!" .... Its Jonny!!

Anyways, you can have the main.cpp function prototypes in a .h file to increase readability and management.

Class interface and implementation (Function prototypes and definitions)
.h
.cpp

Main Prototypes Functions and definitions
.h
.cpp

driver, main or client
main.cpp

have fate!
Last edited on
How can I with functions in header file modifed variables in .cpp file.
for example:
main.cpp:
1
2
3
4
5
6
7
8
9
10
11
# include <iostream>
using namespace std;
#include "funk.h" 

int k=5; //global variabl

void main () {	

	s();
	cout<<k;
}


header funk.h
1
2
3
4
5
6
7
8
9
10
#ifndef funk
#define funk

void s();

void s() {
	k=555;
}

#endif 

it notfy me an error:
Error 1 error C2065: 'k' : undeclared identifier c:\documents and setting....\stek.h

Error 2 error C2371: 'k' : redefinition; different basic types c:\documents and setting....\main.cpp 15

Is it posibile and how.
Can I do this with new .cpp file and how do it.

//I need to reduce space in my main.cpp but how can I do it by cuting code to other cpp.

and how can I add new .cpp file and with function in it modifed a gloabal variabla.





Last edited on
Topic archived. No new replies allowed.
Pages: 12