Shadow Blade
Morrowland Presents Apron Tutorials
game - design - multimedia - web - programming - tutorials - There are currently viewers visiting Apron Tutorials.
   
 
TECHNICAL
GRAPHICAL
SOUND
GAME
WEB
ARTICLE
TOOL
PROJECT
 
 NEWS

  news

  history


 TECHNICAL TUTORIALS

  opengl

  direct3d

  c/c++

  visual basic

  java

  c#


 WEB TUTORIALS

  html

  dhtml

  asp

  php


 IMAGE EDITING

  photoshop

  draw sketch


 3D MODELING

  3d studio


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 DEMOS

  win32 api


 ARTICLES

  general

  opengl


 COMMUNITY

  about us

  credit

  contact












// the file name of this header file is MyHeader.h

#ifndef _MYHEADER_H // if not defined
#define _MYHEADER_H // define MyHeader

#include <stdio.h> // we can now include our extern files here
#include <iostream>		
using namespace std;


// declare function 1 in our new header file
void myFunc_1();
// declare function 2 with an argument in our new header file
void myFunc_2(int y);
// declare function 3 with an argument in our new header file, returns an integer
int  myFunc_3(int z);	

#endif // end if not defined, and end the header file


/*
This is how I setup a standard header files in c/c++
this method makes shure the header file is only defined once
#ifndef _NAME_H
#define _NAME_H

// header file content


#endif
*/




// important remember to include our new header file 
// (we use "" because the file is in our program folder.)
#include "myheader.h"


int mySum1; // declare variables integer (global for this cpp file) 	
int mySum2; // when a variable is declared on the top, outside the functions
int x; // it means that all the functions in this cpp-file have access it.


int main()				
{	

	x = 5;
	myFunc_1(); // call function 1
	cout << mySum1 << endl; // display mySum1


	myFunc_2(5); // call function 2
	cout << mySum2 << endl; // display mySum2


	// display the returned value of function 3
	cout << myFunc_3(5) << endl;

	getchar(); // wait until a key is pressed

	return 0; // return zero;
}


// define function 1
void myFunc_1()
{
	mySum1 = x + 5;
}

// define function 2 with an argument
void myFunc_2(int y)
{
	mySum2 = y + 3;
}

// define function 3 with an argument, must return an integer
int myFunc_3(int z)	
{

	return  z + 2;
}


/*

Learn to use a header file in c/c++.
This program is the same program as in the Function Tutorial.
The only difference is that this program uses an extra header file.


The header file can be used to gain global access to your functions.
(The Source Tutorial will demonstrate this.)
It can also be used to obtain more structured programming as 
your program grow larger.

*/



Download The Source Code! Download Visual C++ Source Code


I hope you found this c++ tutorial useful!

Don't forget to mention Apron Tutorials in your References!

Best Regards
Ronny André Reierstad

 LINKS

  morrowland home



 GAME DEVELOPEMENT

  nvidia

  gamedev

  polycount


 PROJECTS

  shadow blade

  game environment

  virtual 3d guide

  billy blue flame


 MATH AND PHYSICS

  mathworld

  physicsworld







PLEASE LINK TO


  All rights reserved Morrowland © 2011  
Ronny André Reierstad