2

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.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
e.s. kohen
  • 213
  • 1
  • 4
  • 21

1 Answers1

2

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 explicit qualifier, 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).

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
  • I saw that same video: http://channel9.msdn.com/Series/C9-Lectures-Stephan-T-Lavavej-Core-C-/STLCCSeries6 ... Unfortunately, I had removed explicit as he recommended, and then put them back in when I couldn't figure out why I couldn't qualify my constructor name. So answer: No qualification & remove explicit works. I have no idea if this lack of qualification will imply dubious things. Thanks! – e.s. kohen Jan 15 '13 at 22:07