I have read a bunch of information on classes, but I am still confused about something. In Java, a class was a self-contained entity in that if I made a Car class there were two things:

1. A Car.java file that contained all of the member functions and data


2. The instantiation of the object in another file. Of course, the class could be created within another class, but typically, at least in my experience, the Car class would be in a seperate file. I would then instantiate the object and access its functions.


To me, this was very intuitive. Now with C++ it appears to be a little different. With C++ the way understand it is that there are three things:

1. Class definition which would be something similar to this:

Code:
class Car
{
      public:
                int speed;
                int mileage; 
                int getSpeed();
                void setSpeed(int speed);
                int getMileage();
                void setMileage(int mileage);
             
};

2. Class implementation which would be something similar to this:

Code:
int Car::getSpeed()
{
     return (speed);
}

void Car::setSpeed(int speed2)
{
      speed = speed2;
}

int Car::getMileage()
{
     return (mileage);
}

void Car::setMileage(int mileage2)
{
      mileage = mileage2;
}

3. Then in a seperate file, typically at least, you would instantiate an object of the class to access its functions and data. Now do you put all of this in a .hpp (the class definition and class implementation) and then #include it where you want it? Are the class definition and class implementation put in the same file? For instance:

Car.hpp

Code:
#include <iostream>

using namespace std;

class Car
{
      public:
                int speed;
                int mileage; 
                int getSpeed();
                void setSpeed(int speed);
                int getMileage();
                void setMileage(int mileage);
             
};

int Car::getSpeed()
{
     return (speed);
}

void Car::setSpeed(int speed2)
{
      speed = speed2;
}

int Car::getMileage()
{
     return (mileage);
}

void Car::setMileage(int mileage2)
{
      mileage = mileage2;
}
Driver.cpp

Code:
#include <iostream>
#include "Car.hpp"
using namespace std;

int main()
{
    Car car;
    car.setSpeed(100);
    cout<<"The speed is: "<<car.getSpeed()<<"\n";
    cin.ignore();
    cin.get();
}

I realize that this is really a silly class, but I was just using it to try to help get my point across. When people make classes do they make them and then #include the .hpp file in the other classes they want to use it in or do they typically just put the class directly in that file?

On this site (http://www.cprogramming.com/tutorial/lesson12.html) they directly put the class code in the file, but to me this seems to get rid of a certain level of abstraction. If it's in another file you know when I instantiate an object I have access to these functions and this member data without having to know any of the inner workings.

Sorry if this doesn't make a lot of sense. I have the idea in my head; I am just having trouble communicating it. Thanks in advance guys.