File Types

I was wondering how the .h and .cc files work together. I am trying to make a program that uses the two files but I can figure out what I would use each file for. Would I just use the .cc file declare, call, and use the functions, and define the functions in the .h file?

Any help would be great!
Usually, class declarations are stored in their own header files. Member
function definitions are stored in their own .cc files.

Example of a header file (.h)...
1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef AnyClass_H
#define AnyClass_H

class AnyClass
{
private:
	double num1;
	double num2;
public:
	AnyClass();
	AnyClass(double, double);
}
#endif 


Example of the .cc file...
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "AnyClass.h"

AnyClass::AnyClass()
{
	num1 = 0.0;
	num2 = 0.0;
}

AnyClass::AnyClass(double n1, double n2)
{
	num1 = n1;
	num2 = n2;
}
Last edited on
Thanks so much. That helps a lot!
Topic archived. No new replies allowed.