Click here to Skip to main content
13,254,754 members (51,379 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I inherited some C++ code and it has me stumped.

Have a class declared like so.
class CIENavigator :  public CWTLAxControl<CIENavigator,iWebBrowser2>
Instance like so
CIENavigator CIE;
CIENavigator * pCIE = &CIE;

Gets this compile error
1>.\IENavigator.cpp(446) : error C2440: 'initializing' : cannot convert from 'IWebBrowser2 **' to 'CIENavigator *'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Although CIE is declared as CIENavigator, it thinks the type of &CIE to be IWebBrowser2 **

If I force the cast like so:
CIENavigator CIE;
CIENavigator * pCIE = (CIENavigator *) &CIE;

It compiles, but the pointer is indeed the wrong pointer.

I note the class name appears in the declaration of itself, but I don't know what the significance of that is.
I'm not up on Class templates.

How do I get the right CIENavigator object (CIE) address?
Posted 21-Apr-12 11:17am
Updated 21-Apr-12 12:04pm
Nelek 21-Apr-12 17:05pm
Added code tags
xComaWhitex 21-Apr-12 19:18pm
Why are you even using C style casting, which are error prone and doesn't show your intention on casting? I think you need to read up on casting.
Nelek 22-Apr-12 18:34pm
Was it a comment for me?
xComaWhitex 22-Apr-12 18:37pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Answer is the & operator was overloaded to return a different type.

Also, since the & operator did not produce the address of the object, a workaround:

CLASSfoo foo[1];
CLOSSfoo *pfoo = foo; //since C still treats arrays as pointer to first element.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171114.1 | Last Updated 22 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100