• error c2129:静态函数已声明但未定义


    今天在做一个c函数暴露给lua 时,出现这个问题。

    大概代码是这样的,

    头文件:

    #ifndef LEVEL_DESIGNER_H
    #define LEVEL_DESIGNER_H
    extern "C" {
    #include "lualib.h"
    #include "tolua_fix.h"
    }
     
    static int saveFileDialog(lua_State *tolus_S);
    static int openFileDialog(lua_State *tolus_S);
     
    int open_windows_lua(lua_State *tolus_S);
     
    #endif

    源文件:

     1 #include "LevelDesignerUtils.h"
     2  
     3 #include <afxwin.h>         // MFC 核心组件和标准组件
     4 #include <afxext.h>         // MFC 扩展
     5  
     6 #include <afxdisp.h>        // MFC 自动化类
     7  
     8 //wchar to char
     9 void TC2C(const PTCHAR tc, char * c)
    10 {
    11 #if defined(UNICODE)
    12     WideCharToMultiByte(CP_ACP, 0, tc, -1, c, wcslen(tc), 0, 0);
    13     c[wcslen(tc)] = 0;
    14 #else
    15     lstrcpy((PTSTR)c, (PTSTR)tc);
    16 #endif
    17 }
    18  
    19 static int openFileDialog(lua_State *tolus_S)
    20 {
    21     // TODO: 在此添加命令处理程序代码
    22     CFileDialog *dlg = new CFileDialog(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("json文件(*.json)|*.json|配置文件(*.dat)|*.dat|所有文件(*.*)|*.*||"));
    23     INT_PTR nResponse = dlg->DoModal();
    24     CString filPath = "";
    25     if (IDCANCEL == nResponse)
    26     {
    27         delete dlg;
    28     }
    29     else if (IDOK == nResponse)
    30     {
    31         filPath = dlg->GetPathName();
    32         delete dlg;
    33     }
    34     char filepathc[MAX_PATH];
    35     TC2C(filPath.GetBuffer(), filepathc);
    36     lua_pushstring(tolus_S, filepathc);
    37     return 1;
    38 }
    39  
    40 static int saveFileDialog(lua_State *tolus_S)
    41 {
    42     CFileDialog *dlg = new CFileDialog(false, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("json文件(*.json)|*.json|配置文件(*.dat)|*.dat|所有文件(*.*)|*.*||"));
    43     INT_PTR nResponse = dlg->DoModal();
    44     CString filPath = "";
    45     if (IDCANCEL == nResponse)
    46     {
    47         delete dlg;
    48     }
    49     else if (IDOK == nResponse)
    50     {
    51         filPath = dlg->GetPathName();
    52         delete dlg;
    53     }
    54     char filepathc[MAX_PATH];
    55     TC2C(filPath.GetBuffer(), filepathc);
    56     lua_pushstring(tolus_S, filepathc);
    57     return 1;
    58 }
    59  
    60  
    61 int open_windows_lua(lua_State *tolus_S)
    62 {
    63     lua_register(tolus_S, "win_openFileDialog", openFileDialog);
    64     lua_register(tolus_S, "win_saveFileDialog", saveFileDialog);
    65     return 0;
    66 }

    后来翻阅,查出原因:

      静态函数只能在声明它的文件当中可见,不能被其他文件所调用,也就是说静态函数只能在声名它的文件中调用,在其他文件里是不能被调用的。

    当然,其实我这里在头文件里做静态函数的声明也是完全没有必要的。去除后,就可以了。

    原文链接:https://www.cnblogs.com/JhonKing/p/5736059.html

  • 相关阅读:
    【英语天天读】Places and People
    【OpenCV学习】错误处理机制
    【英语天天读】Heart of a stranger 陌生的心灵
    【英语天天读】第一场雪
    【OpenCV学习】角点检测
    【英语天天读】Life is What We Make It
    【英语天天读】培养自信
    【英语天天读】Perseverance
    【OpenCV学习】cvseqpartition序列分类
    【英语天天读】自然
  • 原文地址:https://www.cnblogs.com/ranson7zop/p/8031108.html
Copyright © 2020-2023  润新知