Search code examples
c++class

Is it possible to define multiple classes in just one .cpp file?


I'm working on a project for school and the instructor insists that all code go into one .cpp file (for easier grading on his part). I would like to define multiple classes within this file. Will I run into any problems in doing this?


Solution

  • There is no rule you have to follow (unlike in Java, where each file can only contain one public top-level class). You're free to place and name classes in however named files you like (besides the suffix).

    However its another question if that is good practices (its not!).