Skip to content

Instantly share code, notes, and snippets.

@DavidYKay
Created July 7, 2016 21:10
Show Gist options
  • Save DavidYKay/22226bff98cba3d8b1223bd200bb12bc to your computer and use it in GitHub Desktop.
Save DavidYKay/22226bff98cba3d8b1223bd200bb12bc to your computer and use it in GitHub Desktop.
C++ Class / Header file example
#import "Car.h"
const int ACCELERATION_FACTOR = 10;
const int BRAKING_FACTOR = 30;
Car::Car() {
speed = 0;
}
void Car::accelerate(float intensity) {
speed = speed + ACCELERATION_FACTOR * intensity;
}
void Car::brake(float intensity) {
speed = speed - BRAKING_FACTOR * intensity;
}
class Car
{
public:
Car();
void accelerate(float intensity);
void brake(float intensity);
private:
int speed;
}
Car *myCar = Car::Car();
myCar->accelerate(1.0);
myCar->brake(0.5);
@JSquar
Copy link

JSquar commented Oct 11, 2018

Try

#include"panel.h"
panel::panel()
{
    this->x = 0;
}/** end construction */

void panel::set_x( int x )
{
    this->x = x;
}/** end method */

and build with g++ -o main.x main.cpp panel.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment