Created
July 7, 2016 21:10
-
-
Save DavidYKay/22226bff98cba3d8b1223bd200bb12bc to your computer and use it in GitHub Desktop.
C++ Class / Header file example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Car | |
{ | |
public: | |
Car(); | |
void accelerate(float intensity); | |
void brake(float intensity); | |
private: | |
int speed; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Car *myCar = Car::Car(); | |
myCar->accelerate(1.0); | |
myCar->brake(0.5); |
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
Can you re-post with cleaner look ? Difficult to understand the issue from this copy/paste.