Note 16.11.1.
In a perfect world, it might be nice to only list the public members in the .h file. But the .h file needs to have the complete class declaration minus the function definitions.
Point.h
and Point.cpp
.
// Header guard
#ifndef SIMPLE_POINT_H
#define SIMPLE_POINT_H
// Include any libraries that are referenced here in the .h
// such as <string>
/**
* @brief Represents a point in 2D space.
*
*/
class Point {
public:
/**
* @brief Construct a new Point object
*
* @param x starting x coordinate
* @param y starting y coordinate
*/
Point(double x, double y);
/**
* @brief Get the x coordinate of the point
*
* @return double x coordinate
*/
double getX();
private:
double m_x;
double m_y;
};
#endif // SIMPLE_POINT_H
// Include <cmath> or any other needed libraries
// Include the header file for the Point class
#include "Point.h"
// possibly use using namespace std;
Point::Point(double x, double y) {
m_x = x;
m_y = y;
}
double Point::getX() {
return m_x;
}
$ g++ Point.cpp main.cpp -o program.exe
Student.h
header file?
class Student {
public:
Student(int age, int id, string year);
Student(string year);
void increment(int age);
void print();
bool isJunior();
private:
// Instance variables
int m_age, m_id;
string m_year;
};
void Student::print() {...}
.
isJunior
function.
Student::m_age = 0;