Mar 11, 2011

C++ Error: No matching function call

no matching function for call to 'SomeNamespace:: SomeClass:: SomeClass()

This can be a confusing error when "SomeClass()" is something you don't even think you're using. For instance given this class fragment:

SNAGHTMLcb631cc

and this constructor

SNAGHTMLcb76930

You get this error:
no matching function for call to 'SyncorLibrary::Rectangle::Rectangle()'  

Yet this constructor isn't calling a Rectangle constructor. Or is it? If you look at the private members you'll see an instance of m_entryRect that is a Rectangle. This error is telling you that since you didn't explicitly construct the  Rectangle  the compiler is trying to do it for you, and failing because there is no default constructor.  If you put the explicit constructor inside the braces it's not going to help. The compiler will still try the default constructor when it comes to the end of the initializer list. You must add the constructor to the initializer list as shown below.

SNAGHTMLcbf8d05

About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.