What you need to do is to use the views_field_view module in combination with the entity reference module to build this. Enable both modules.
In your teacher content type create a entity reference field which reference the class that they teach (let call this field_relate_class).
Then you need to create a view of teachers as child view with a contextual filter using field_relate_class. The setting of the contextual filter should be following:
When the filter value is NOT available -> Provide default value -> Content ID From URL
When the filter value IS available or a default is provided -> Specify validation criteria -> Basic validator.
Then you need to create views of classes. Add the Content id field and add a Global Views field(views_field_view provide Global View). Make sure content id field is on top of Global Views field.
Once the Global Views field is added. Click on this field, the UI will populate setting for you to select the Views you want to display in this field. Select teacher views you created. There is a Contextual Filter Text box on this setting just fill the token of Content ID. Then Click Save. You are done.
Let me know if you find it difficult in this process.