Delegated Construction Question:
Compiler Error C2039: ‘{ctor}’ is not a member of Logging::LogManager
I am using Microsoft’s C++ November 2012 CTP Compiler, not the default one in Visual Studio 2012, so I have access to new C++ features, (variadic templates, etc).
I am trying to get delegated construction to work using namespaces and header files… I am not certain if this falls under the base constructor inheritance features yet to be implemented in Visual Studio 2012; so, it may be the case that I shouldn’t expect this to work:
How do you do this in C++ 11?
// LogManager.h extract
namespace Logging {
class LogManager
{
private:
static std::wstring defaultFileName;
explicit LogManager(std::wstring logFileName);
explicit LogManager();
~LogManager(void);
}
// LogManager.cpp extract
/********************************************************************
*****/
Logging::LogManager::LogManager(std::wstring fileName)
{}
/********************************************************************
*****/
Logging::LogManager::LogManager()
: LogManager(defaultFileName) // Yields C2664
// : Logging::LogManager::LogManager(defaultFileName) // Yields C2039
// : Logging::LogManager(defaultFileName) // Yields C2614
{}
error C2039: ‘{ctor}’ : is not a member of ‘Logging::LogManager’
error C2614: ‘Logging::LogManager’ : illegal member initialization: ‘LogManager’ is not a base or member
error C2664: ‘Logging::LogManager::LogManager(const Logging::LogManager &)’ : cannot
convert parameter 2 from ‘std::wstring’ to ‘const Logging::LogManager &’
Answer::
Cannot use explicit keyword in header file per known bug already known to Microsoft.
Only the first signature will work of the Constructor will work with this .. workaround.
This appears to be a bug in the CTP. It also shows up during this presentation by Stephan T. Lavavej (see from min 38:45).
The only possible workaround is to drop the
explicitqualifier, if that’s acceptable in your project. Otherwise, just avoid delegating to an explicit constructor.In particular, this is not related to inherited constructors, which is a different feature and is not supported by the CTP (as Stephan T. Lavavej says in the same presentation I linked – just a few minutes after the bug occurs).