Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / January 2007

Tip: Looking for answers? Try searching our database.

Error C2385 on (ctor)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
PLS - 11 Jan 2007 01:37 GMT
I'm converting some C++ code to VC++ 2005 in native (non-managed) mode.
This code doesn't use ATL, but codes the COM mechanisms directly.

It has a class which is the equivalent of ATL's IDispatchImpl:

template<class T>
class CDispatch : virtual public IDispatch, virtual public CUnknown,  
   private CDispatchBase
 {
    ...

   CDispatch::CDispatch(IUnknown *pOuterUnknown)
     : CUnknown(pOuterUnknown),
       m_pITypeInfo(0)
     {}

    ...
 };

The constructor produces this error:

c:\project\pciw\cdisp.h(253) : error C2385: ambiguous access of '{ctor}'
       could be the '{ctor}' in base 'IDispatch'
       or could be the '{ctor}' in base 'CUnknown'
       or could be the '{ctor}' in base 'CDispatchBase'
       c:\project\pciw\cdisp.h(285) : see reference to class template    
         instantiation 'CDispatch<T>' being compiled

I understand about name collisions and disambiguation for methods in
multiple inheritance. How do you disambiguate a constructor?

Seriously, how do I fix this?

 Thanks,
   ++PLS
Vladimir Nesterovsky - 11 Jan 2007 09:08 GMT
1. Is it correct that CDispatchBase inherits CUnknown (non virtually)? Is it
your intention?
2. Can you define CDispatch constructor this way:

CDispatch::CDispatch(IUnknown *pOuterUnknown)
    : CDispatch::CUnknown(pOuterUnknown),
      m_pITypeInfo(0)
{}

?

> I'm converting some C++ code to VC++ 2005 in native (non-managed) mode.
> This code doesn't use ATL, but codes the COM mechanisms directly.
[quoted text clipped - 26 lines]
> I understand about name collisions and disambiguation for methods in
> multiple inheritance. How do you disambiguate a constructor?

Thanks.
--
Vladimir Nesterovsky
PLS - 11 Jan 2007 21:48 GMT
Changing the constructor as you suggest gives exactly the same error.
And I get that error without the virtuals in the class declaration.

CDispatchBase has no base classes.

IDispatch has IUnknown as a base class.

CUnknown has IUnknown as a base class.

And removing CUnknown and "virtual" from the CDisp base classes gives a
very similar error message:
c:\project\pciw\cdisp.h(253) : error C2385: ambiguous access of '{ctor}'
       could be the '{ctor}' in base 'IDispatch'
       or could be the '{ctor}' in base 'CDispatchBase'
       c:\project\pciw\cdisp.h(284) : see reference to class template
          instantiation 'CDispatch<T>' being compiled

I'm stumped. It looks like C++ 2005 just can't handle multiple
inheritance. Any base class is going to have a constructor.

   ++PLS

> 1. Is it correct that CDispatchBase inherits CUnknown (non virtually)? Is it
> your intention?
[quoted text clipped - 41 lines]
> --
> Vladimir Nesterovsky
Ben Voigt - 11 Jan 2007 23:19 GMT
> Changing the constructor as you suggest gives exactly the same error.
> And I get that error without the virtuals in the class declaration.
[quoted text clipped - 15 lines]
> I'm stumped. It looks like C++ 2005 just can't handle multiple
> inheritance. Any base class is going to have a constructor.

Have you tried the Comeau online compiler?  If it accepts the code then
Visual C++ definitely has a bug.  If not, it may yield a much clearer error
message.

>    ++PLS
>
[quoted text clipped - 45 lines]
>> --
>> Vladimir Nesterovsky
PLS - 12 Jan 2007 02:02 GMT
> Comeau online compiler

Actually, that helped. Thank you.

Here's what the problem is:

template<class T>
class CDispatch : virtual public IDispatch, virtual public CUnknown,
private CDispatchBase
 {
    ...

   CDispatch::CDispatch(IUnknown *pOuterUnknown)
     : CUnknown::CUnknown(pOuterUnknown),
       m_pITypeInfo(0)
     {}

   CDispatch::~CDispatch()
     {
       if (m_pITypeInfo != NULL)
         {
           m_pITypeInfo->Release();
         }
     }

    ...
 };

The Comeau compiler tells me:
"ComeauTest.c", line 379: error: qualified name is not allowed in member
declaration
     CDispatch::CDispatch(IUnknown *pOuterUnknown)

Remove the "CDispatch::" from these two methods and everything works.

I guess this is a restriction in the new C++ standard. Can anyone
confirm this?

I think this is a compiler bug, because of the horribly off target
message. Can anyone tell me how to file a bug report?

 Thanks,
   ++PLS
Ben Voigt - 12 Jan 2007 17:09 GMT
>> Comeau online compiler
>>
[quoted text clipped - 28 lines]
> declaration
>      CDispatch::CDispatch(IUnknown *pOuterUnknown)

Oh, your functions are defined inside the class declaration block,
definitely you shouldn't double up the class name.

> Remove the "CDispatch::" from these two methods and everything works.
>
> I guess this is a restriction in the new C++ standard. Can anyone
> confirm this?

I think you were instructing the compiler to look for a nested class.

> I think this is a compiler bug, because of the horribly off target
> message. Can anyone tell me how to file a bug report?

https://connect.microsoft.com/feedback/default.aspx?SiteID=210

>  Thanks,
>    ++PLS

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.