Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

class

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?

like image 855
Chad Avatar asked Dec 07 '09 17:12

Chad


2 Answers

Yes, you can. This is easily verifiable.

class C
{
};

class D
{
};

int main(int argc, char**argv)
{
  return 0;
}
like image 59
Brian R. Bondy Avatar answered Sep 24 '22 19:09

Brian R. Bondy


There is no rule you have to follow (like in java). 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!).

like image 41
RED SOFT ADAIR Avatar answered Sep 21 '22 19:09

RED SOFT ADAIR