Weird error when defining variables

时间:2015-10-30 22:15:01

标签: c++ lua

So, I'm trying to use Lua C Api on a game, but I'm having some errors defining the variables in a .cpp file

I have a library called CLua.h where I define all of the stuff that I'm using in the following code, and it compiles fine. (I will not be sharing it, because it's pretty valuable and highly sought after for the game that I'm using this in, don't want anybody else to have my work, but either way there's no problem with the library)

#include <iostream>
#include <Windows.h>
#include <string>
#include "CLua.h"

using namespace std;

void CLua::Init(){
Lua_tolstring = (Lua_tolstring)0x00517f70;
Lua_getfield = (Lua_getfield)0x00516d70;
Lua_pcall = (Lua_pcall)0x00517340;
}

For starters, on the #include line, I'm getting an error called "PCH warning" on the #

Then, when I define all of the Lua states farther down, on the = sign, I get an error saying it expected an identifier

1 个答案:

答案 0 :(得分:2)

If I am understanding your issue correctly, it looks like you are naming your variables the same as the class name. For example, you cannot name an int variable 'int'.

So, if your class name is 'Lua_tolstring', you must name your variable something else. (Even if it's just a different mixed case name) For example:

Lua_tolstring Lua_tolstring; //Bad
Lua_tolstring variableName; //Good

Then it would be used as such:

variableName = (Lua_tolstring)0x00517f70;

My best guess is that the variable you are trying to set in the CLua class is not actually named 'Lua_tolstring'. Seeing your header file would help. In any case, double check you are accessing the right variable. (VaRiaBLE naMEs Are CaSe SensiTIVe!)

相关问题