[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Compiler Grabs Wrong Overload

Posted on 2006-04-15
Medium Priority
Last Modified: 2010-04-01
I have a class that contains two different versions of the same function called GetZip().  In one version, it uses CStrings that are themselves pointed to controls, in the other, it uses the controls themselves.

The two are declared thus:

int GetZip(CDialog *pParent,struct dbffile *amaf08z,CString *pCity, CString *pState, CString *zip);
int GetZip(CDialog *pParent,struct dbffile *amaf08z, CCapEdit *pCtrlCity, CStateCombo *pCtrlState, COXMaskedEdit *pCtrlZip);

where CCapedit is a control derived from CEdit, CStateCombo is derived from CComboBox, and COXMaskedEdit is a third party Masked Editor derived from CEdit.

The call that accesses the  controls directly is used throughout the program in various dialogs, and works, as advertised, except in one case where the compiler insists on latching onto the one that uses CStrings.

Since I have both versions to work with, it is easy enough to rewrite the call to use the variables rather than the controls, but what is going on here?  I am very concerned that I have some issues that need to be dealt with now in the proper fashion, rather than just designing a work-around.

1.  I thought about an errant header file, and there is only one header on the system where GetZip in mentioned.
2.  I thought that perhaps name mangling is the culprit (A CString looks like a Control to the name mangler), but I can't find any way to view the name mangled output.  Something like -P or -E in a traditional 'c' compiler.  If this is the case, why would it work elsewhere in the same program, albiet a different source file?
3.  In this source file, the (I think they are called tooltips) window that comes up after the first '(' knows that both instances are available.  As a matter of fact, the overload that uses controls is the first one mentioned.

Any help that you can offer will be greatly appreciated.

Thanks in advance, Rick

Question by:rickatseasoft
LVL 11

Assisted Solution

WelkinMaze earned 450 total points
ID: 16460463
Is there enough information in your calls of the functions for the compiler to recognize the passed parameters. Maybe it treats them just as pointers?
LVL 14

Assisted Solution

PockyMaster earned 450 total points
ID: 16460526
If you explicitly cast your variables in your call, will it still go the wrong way?
LVL 86

Accepted Solution

jkr earned 600 total points
ID: 16460627
Can you post the code in question?

>>but I can't find any way to view the name mangled output.

Set the linker to generate a map file, you'll find the mangled name there.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question