简体   繁体   中英

error C2440: '=' : cannot convert from 'char *(__cdecl *)(int,int)' to en 'GetItemText_t'

I get an error in a code( the code isn't mine,it was just released on an other website)

I get this error :

error C2440: '=' : cannot convert from 'char *(__cdecl *)(int,int)' to en 'GetItemText_t'

Here is the code :

char* TheatreMenu_GetItemText(int index, int column)
{
    if( index >= 0 && index < uiDemoInfo.numDemos)
    {
        switch(column)
        {
        case 0:
            return uiDemoInfo.demos.at(index).demoName;
            break;
        case 1:
            return UI_LocalizeMapName(uiDemoInfo.demos.at(index).mapName);
            break;
        }
    }
    return "";
}

void PatchMW2_TheatreMenu()
{
    TheatreMenu_Feeder.feeder = 10.0f;
    TheatreMenu_Feeder.GetItemCount = TheatreMenu_GetItemCount;
    TheatreMenu_Feeder.GetItemText = TheatreMenu_GetItemText;
    TheatreMenu_Feeder.Select = TheatreMenu_Select;

    UIFeeders.push_back(TheatreMenu_Feeder);

    AddUIScript("loadDemos", TheatreMenu_UIScript_LoadDemos);
    AddUIScript("FixDemoServer", TheatreMenu_UIScript_FixDemoServer);
    AddUIScript("LaunchDemo", TheatreMenu_UIScript_LaunchDemo);

    strcpy((char*)(0x6FB620), "oldrec");
    strcpy((char*)(0x708238), "oldstoprec"); 

    Cmd_AddCommand("record", customRecordFunc, &customRecord, 0);
    Cmd_AddCommand("stoprecord", customStopRecordFunc, &customStopRecord, 0);
}

The error is from this line :

TheatreMenu_Feeder.GetItemText = TheatreMenu_GetItemText;

I hope you will help me quickly, thanks in advance.

Cordially, Chris

TheatreMenu_GetItemText is a function name, I'm not sure the type of TheatreMenu_Feeder.GetItemText because UIFeeder_t TheatreMenu_Feeder; while you hadn't support the definition of UIFeeder_t .

what makes this error ? You may check the UIFeeder_t.GetItemText 's definition.Is it same as TheatreMenu_GetItemText 's definition ?


BTW , about this function .

char* TheatreMenu_GetItemText(int index, int column)
{
    if( index >= 0 && index < uiDemoInfo.numDemos)
    {
        switch(column)
        {
        case 0:
            return uiDemoInfo.demos.at(index).demoName;
            break;
        case 1:
            return UI_LocalizeMapName(uiDemoInfo.demos.at(index).mapName);
            break;
        }
    }
    return "";
}

the final line ,I think return NULL may better. Of course , if here changed , some related code may need corresponding change

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM