CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Classes with methods defined externally

As with functions in C11, we can separate the declarations and definitions of C++ methods.

As with C11, we employ header files to provide the declarations - this 'thing' exists elsewhere, and then define (implement) the method in a C++ source file:

#include <iostream>

// myvector.h - header file

class Point {
public:
    double x, y;

    void   offset(double offsetX, double offsetY);
    void   print(void);
};

class MyVector {
public:
    Point start, end;

    void  offset(double offsetX, double offsetY);
    void  print(void);
};

 


CITS2002 Systems Programming, Lecture 23, p6, 17th October 2023.