Putting class declaration in .cpp file

前端 未结 3 2030
不思量自难忘°
不思量自难忘° 2020-12-09 09:13

Is it possible to have class declaration and implementation in same .cpp file?

I want to do some unit-testing with help of mock object. Here is some example of my te

3条回答
  •  鱼传尺愫
    2020-12-09 10:04

    Yes, it's entirely legitimate and allowable to define a class and its member functions in a single file. In fact, from the viewpoint of the compiler that's essentially always the case -- you have the class definition in a header, and include that header in the source file where you implement its member functions.

    The errors you've encountered look like linker errors, not compiler errors. Exactly what's missing isn't entirely clear from what you've posted. One possibility is that your base class has some pure virtuals that you've failed to implement in the derived class, but I'm not at all sure that's correct.

提交回复
热议问题