Skip to content

Instantly share code, notes, and snippets.

@dadarek
Created June 29, 2012 20:41
Show Gist options
  • Save dadarek/3020517 to your computer and use it in GitHub Desktop.
Save dadarek/3020517 to your computer and use it in GitHub Desktop.
C++ Car
#include <iostream>
using namespace std;
class Engine
{
public:
Engine(){
cout << "Engine constructor" << endl;
}
void run()
{
cout << "I'm running ..." << endl;
}
};
class Wheels
{
public:
Wheels(){
cout << "Wheel constructor" << endl;
}
void spin()
{
cout << "I'm spinning ... " << endl;
}
};
class Doors
{
public:
Doors(){
cout << "Doors constructor" << endl;
}
void open()
{
cout<< "I am opening the doors" << endl;
}
};
class Car
{
public:
Wheels* wheels;
Engine engine;
Doors* doors;
};
int main()
{
Wheels wheels;
Doors doors;
Car car;
car.wheels = &wheels;
car.doors = &doors;
car.wheels->spin();
car.engine.run();
car.doors->open();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment