Recent Changes - Search:

Coding C++

Computing

Header Files

Trail Index | Header Files

When you should make, and use, your own header files.

DataPoint.hh

/*
 * Header file
 * Put in this a definition of the class,
 * and possibly the simplest, one-line functions
 * as "inline"
 */


/*
 * prevent multiple definitions
 * by defining a unique symbol
 */

#ifndef DATAPOINT_HH
#define DATAPOINT_HH

class DataPoint {
public:
        DataPoint(double x,double y, double z);
        inline double getX() const {
                return x;
        }
        double distance(DataPoint p);
private:
        double x,y,e;
};
#endif //DATAPOINT_HH

DataPoint.cc

#include "DataPoint.hh"
#include <cmath>

/*
 * implementation of the method declared in the header
 */

double DataPoint::distance(DataPoint p) {
        return sqrt(pow(x-p.x,2),pow((y-p.y)/e,2));
}

DataPointUser.cc

/*
 * this program uses the DataPoint class
 */


// in the source, you only need to include the header
#include "DataPoint.hh"
#include <iostream>

int main() {
        using namespace std;
        DataPoint p1;
        DataPoint p2;
        cout << p1.distance(p2) <<endl;
}

< Container String | Trail Index | References and Pointers >

Edit - History - Print - Recent Changes - Search
Page last modified on April 11, 2007, at 02:38 am