473,513 Members | 2,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moved code won't compile

I had this code previously:

void App::FillFontBox(HWND PrefsBox)
{
[snipped]

EnumFontFamilies(hdc,(LPCTSTR)NULL,(FONTENUMPROC)E numFontNamesProc,(long)this);

[snipped]

sort(FontNames.begin(), FontNames.end(), CaselessCmp);

[snipped]

return;
}

int CALLBACK App::EnumFontNamesProc(ENUMLOGFONT FAR *lpelf,
NEWTEXTMETRICFAR*lpntm,intFontType, LPARAM lParam)

bool App::CaselessCmp(const string& s1, const string& s2)

It compiled fine. (Apologies for the window code, but I'm assuming this
is a C++ problem, rather than an OS specific one.)

I moved much of the code from FillFontBox, and the CALLBACK (__stdcall)
and predicate functions into an existing class:

vector<stringClass_Font::GetTypeFaces()
{
[snipped]

EnumFontFamilies(hdc,(LPCTSTR)
NULL,(FONTENUMPROC)EnumFontNamesProc, (long)NULL);

[snipped]

sort(TypefaceNames.begin(), TypefaceNames.end(), CaselessCmp);

return TypefaceNames;
}

int CALLBACK Class_Font::EnumFontNamesProc(ENUMLOGFONT FAR *lpelf,
NEWTEXTMETRIC FAR *lpntm, int FontType, LPARAM lParam)

bool Class_Font::CaselessCmp(const string& s1, const string& s2)

Now the compiler wants me to use "&Class_Font::CaselessCmp" and when
passing EnumFontNamesProc the compiler gives me "error C2440: 'type
cast' : cannot convert from 'overloaded-function' to 'FONTENUMPROC'"

There's only one EnumFontNamesProc.

Anyone know what's going on here?

Thank you
--
Derek
Nov 3 '07 #1
1 1811
* DerekBaker:
* DerekBaker:
>I had this code previously:

void App::FillFontBox(HWND PrefsBox)
{
[snipped]

EnumFontFamilies(hdc,(LPCTSTR)NULL,(FONTENUMPROC) EnumFontNamesProc,(long)this);
[snipped]
sort(FontNames.begin(), FontNames.end(), CaselessCmp);

[snipped]

return;
}

int CALLBACK App::EnumFontNamesProc(ENUMLOGFONT FAR *lpelf,
NEWTEXTMETRICFAR*lpntm,intFontType, LPARAM lParam)

bool App::CaselessCmp(const string& s1, const string& s2)

It compiled fine. (Apologies for the window code, but I'm assuming
this is a C++ problem, rather than an OS specific one.)

I moved much of the code from FillFontBox, and the CALLBACK
(__stdcall) and predicate functions into an existing class:

vector<stringClass_Font::GetTypeFaces()
{ [snipped]
EnumFontFamilies(hdc,(LPCTSTR)
NULL,(FONTENUMPROC)EnumFontNamesProc, (long)NULL);
[snipped]
sort(TypefaceNames.begin(), TypefaceNames.end(), CaselessCmp);

return TypefaceNames;
}

int CALLBACK Class_Font::EnumFontNamesProc(ENUMLOGFONT FAR *lpelf,
NEWTEXTMETRIC FAR *lpntm, int FontType, LPARAM lParam)

bool Class_Font::CaselessCmp(const string& s1, const string& s2)

Now the compiler wants me to use "&Class_Font::CaselessCmp" and when
passing EnumFontNamesProc the compiler gives me "error C2440: 'type
cast' : cannot convert from 'overloaded-function' to 'FONTENUMPROC'"

There's only one EnumFontNamesProc.

Anyone know what's going on here?

Thank you

Well it wouldn't take EnumFontNamesProc, because I didn't declare it
static.

Now it won't take the predicate!

sort(TypefaceNames.begin(), TypefaceNames.end(), &Class_Font::CaselessCmp);

won't call

bool Class_Font::CaselessCmp(const string& s1, const string& s2)
{[snipped]}

even though the compiler suggests it.

Output [apologies for the length]:
[snipped]

Works now that CasslessCmp is static. That'll teach not to copy and paste, especially when I've got
a headache!.
--
Derek
Nov 3 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1381
by: lkrubner | last post by:
I wrote a PHP content management system and it worked fine on old servers. I just moved it to a new server on Rackspace. I'm trying to debug. At the top of the first file (index.php) I need to...
13
2027
by: AFKAFB | last post by:
Hi Sometimes when i edit previously saved VBA code e.g. To update field names etc the revised code does not work. Even if i copy and paste in a previous version it does not work. The only...
13
2612
by: Skybuck Flying | last post by:
Hi, I would like to split main.c which contains all code into the following Step 1. Machine.h Step 2. drand.h and drand.c Step 3. nrand.h and nrand.c Main.c then only contains some test...
5
6732
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
13
7564
by: R Reyes | last post by:
is there a way to avoid the validateRequest error page in my code behind file? i can't seem to find a way to handle the error w/o an error code or exception being thrown... i am NOT looking for...
10
1795
by: Sourcerer | last post by:
I wrote this very simple code in .NET VC++. I compiled it on my system, and tried to run it on my friend's computer (he doesn't have the compiler). We both have Windows XP Professional. I have .NET...
1
2691
by: mark4asp | last post by:
I moved a page to another web-site and now it's broke! I had 5 pages in their own web-site. These pages have now been moved to another web-site. Everything is fine except that one of the pages,...
8
2300
by: mohammaditraders | last post by:
#include <iostream.h> #include <stdlib.h> #include <conio.h> #include <string.h> class Matrix { private : int numRows, numCols ; int elements ;
1
1073
by: Alex | last post by:
Hi Everyone, To better organize my code I created to Folders in Visual Studio 2005, one for Forms and one for Logic... then I moved the .vb files into the appropriate folders. It worked great...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7535
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7523
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.