Visual C++ Compiler Error C2316: Make with the class definition

Visual C++ Compiler Error C2316

You know, I was getting this error when porting some exception catching code from Visual C++ 6 to version 9. The error message helpfully states that 'exception' cannot be caught as the destructor and/or copy constructor are inaccessible

Weird thing was, it was wrong. Both the copy constructor and destructor for the class and all it’s ancestors were in public scope.

Eventually there was the figuring out: the exception was being anonymously caught, like so:
try {
whatever();
}
catch (MyExceptionClass&) {}

And to keep MSVC6 happy, earlier in the codebase a preceding programmer had coded:
class MyExceptionClass;
Which did indeed keep MSVC6 happy. MSVC9 asked what I’d done with the copy constructor. Well, dear friend: it’s in the header file that wasn’t included. Delete the forward declaration, add one #include and we are cooking with gas.

If we actually give the compiler the definition of the class being caught it can generate code rather than misleading error messages. Why the error message wasn’t: “No definition for this class” is beyond me.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

1 thought on “Visual C++ Compiler Error C2316: Make with the class definition

  1. EvanB

    “Why the error message wasn’t: ‘No definition for this class’ is beyond me”

    I’m not sure how long it would have taken me to figure out that C2316 in this context means a missing class definition. Nearly four years on, your post saves this poor soul at least an hour of his life and MS a great deal of verbal abuse. Thanks.

Comments are closed.