linker error 2005 appears to be caused by a constructor

In your header file:

Card::Card(color c, int v) {

This is a definion of Card‘s constructor. This means that every translation unit (a C++ source file), that #includes this header ends up defining this constructor. Remember that an #include of a header file is exactly equivalent to logically inserting the contents of the header file, verbatim, into the C++ source file that #includes it.

If you have ten C++ source files that include this header this means that each one of the ten C++ source file defines this constructor.

This violates C++’s One Definition Rule, which requires that each (non-inlined) object or function gets defined exactly once. No more, no less.

This explains your compilation error. You simply need to move this constructor’s definitions to exactly one of your C++ source files.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top