Resolving error C2248 with CObject

It can be a frustrating error to try and diagnose. Try commenting out all the code you’ve added since your last checkin and the error is still there? Most likely, this is happening due to a copy constructor being called on an object that derives from CObject. If you are returning a CObject by value, then the copy constructor will be implicitly called. To solve this, either return it by reference or by const-reference, which ever applies to the situation.

Share this:

Related

§ One Response to Resolving error C2248 with CObject

Another useful technique is to insert
#pragma message (“checkpoint keyword\n”)
anywhere in your code and then look at the output window of the compilation.
Once after a few Ctrl-F7 compiles you should be able to find the exact class header file of yours that the compiler does not like.
After that placing pragma messages inside and outside of the class will get you to your “line of code” that is causing CC2248.