Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ WTL
I inherited some C++ code and it has me stumped.
 
Have a class declared like so.
class CIENavigator :  public CWTLAxControl<CIENavigator,iWebBrowser2>
{
public:
...
 
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
mrbll183
Edited 21-Apr-12 12:04pm
Nelek63.2K
v3
Comments
Nelek at 21-Apr-12 17:05pm
   
Added code tags
xComaWhitex at 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 at 22-Apr-12 18:34pm
   
Was it a comment for me?
xComaWhitex at 22-Apr-12 18:37pm
   
Yeah?

1 solution

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

Solution 1

Answer is the & operator was overloaded to return a different type.
from stackoverflow.com.
 
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.
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 329
2 CPallini 270
3 Afzaal Ahmad Zeeshan 204
4 DamithSL 194
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 22 Apr 2012
Copyright © CodeProject, 1999-2014
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