Moved code won't compile

D

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<string> Class_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
 
D

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<string> Class_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]:

c:\program files\microsoft visual studio 8\vc\include\algorithm(3181) : error C2064: term does not
evaluate to a function taking 2 arguments
c:\program files\microsoft visual studio 8\vc\include\algorithm(3237) : see reference to
function template instantiation 'std::pair<_Ty1,_Ty2>
std::_Unguarded_partition<_RanIt,_Pr>(_RanIt,_RanIt,_Pr)' being compiled
with
[
_Ty1=std::_Vector_iterator<std::string,std::allocator<std::string>>,
_Ty2=std::_Vector_iterator<std::string,std::allocator<std::string>>,
_RanIt=std::_Vector_iterator<std::string,std::allocator<std::string>>,
_Pr=bool (__thiscall Class_Font::* )(const std::string &,const std::string &)
]
c:\program files\microsoft visual studio 8\vc\include\algorithm(3261) : see reference to
function template instantiation 'void std::_Sort<std::_Vector_iterator<_Ty,_Alloc>,__w64
int,_Pr>(_RanIt,_RanIt,_Diff,_Pr)' being compiled
with
[
_Ty=std::string,
_Alloc=std::allocator<std::string>,
_Pr=bool (__thiscall Class_Font::* )(const std::string &,const std::string &),
_RanIt=std::_Vector_iterator<std::string,std::allocator<std::string>>,
_Diff=__w64 int
]
c:\documents and settings\derek\my documents\my code\windows\dbclip\class_font.cpp(84) :
see reference to function template instantiation 'void
std::sort<std::_Vector_iterator<_Ty,_Alloc>,bool(__thiscall Class_Font::* )(const std::string
&,const std::string &)>(_RanIt,_RanIt,_Pr)' being compiled
with
[
_Ty=std::string,
_Alloc=std::allocator<std::string>,
_RanIt=std::_Vector_iterator<std::string,std::allocator<std::string>>,
_Pr=bool (__thiscall Class_Font::* )(const std::string &,const std::string &)
]

Anyone help?

Thanks
 
D

DerekBaker

* 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<string> Class_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!.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top