zoukankan      html  css  js  c++  java
  • 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
    

     源文件:

    #include "LevelDesignerUtils.h"
    
    #include <afxwin.h>         // MFC 核心组件和标准组件
    #include <afxext.h>         // MFC 扩展
    
    #include <afxdisp.h>        // MFC 自动化类
    
    //wchar to char
    void TC2C(const PTCHAR tc, char * c)
    {
    #if defined(UNICODE)
    	WideCharToMultiByte(CP_ACP, 0, tc, -1, c, wcslen(tc), 0, 0);
    	c[wcslen(tc)] = 0;
    #else
    	lstrcpy((PTSTR)c, (PTSTR)tc);
    #endif
    }
    
    static int openFileDialog(lua_State *tolus_S)
    {
    	// TODO: 在此添加命令处理程序代码
    	CFileDialog *dlg = new CFileDialog(true, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("json文件(*.json)|*.json|配置文件(*.dat)|*.dat|所有文件(*.*)|*.*||"));
    	INT_PTR nResponse = dlg->DoModal();
    	CString filPath = "";
    	if (IDCANCEL == nResponse)
    	{
    		delete dlg;
    	}
    	else if (IDOK == nResponse)
    	{
    		filPath = dlg->GetPathName();
    		delete dlg;
    	}
    	char filepathc[MAX_PATH];
    	TC2C(filPath.GetBuffer(), filepathc);
    	lua_pushstring(tolus_S, filepathc);
    	return 1;
    }
    
    static int saveFileDialog(lua_State *tolus_S)
    {
    	CFileDialog *dlg = new CFileDialog(false, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("json文件(*.json)|*.json|配置文件(*.dat)|*.dat|所有文件(*.*)|*.*||"));
    	INT_PTR nResponse = dlg->DoModal();
    	CString filPath = "";
    	if (IDCANCEL == nResponse)
    	{
    		delete dlg;
    	}
    	else if (IDOK == nResponse)
    	{
    		filPath = dlg->GetPathName();
    		delete dlg;
    	}
    	char filepathc[MAX_PATH];
    	TC2C(filPath.GetBuffer(), filepathc);
    	lua_pushstring(tolus_S, filepathc);
    	return 1;
    }
    
    
    int open_windows_lua(lua_State *tolus_S)
    {
    	lua_register(tolus_S, "win_openFileDialog", openFileDialog);
    	lua_register(tolus_S, "win_saveFileDialog", saveFileDialog);
    	return 0;
    }
    

     

    后来翻阅,查出原因:

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

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

    Stay hungry, stay foolish!
  • 相关阅读:
    德国闪电战和苏联大纵深,谁更厉害?(一个是为了避免战略上的持久战,一个是为了战役的突破)
    “MEAN”技术栈开发web应用
    MVC 01
    适配器模式
    w3wp占用CPU过高
    安装tensorflow
    MemCache分布式内存对象缓存系统
    MVC 使用IBatis.net
    分布式计算
    Remote Desktop Connection Manager
  • 原文地址:https://www.cnblogs.com/JhonKing/p/5736059.html
Copyright © 2011-2022 走看看