从循环添加到结构 (c++)
Adding to struct from a loop (c++)
所以我正在使用下面的代码,但在尝试从结构中的一行调用文本时遇到错误。
struct lines
{
LPCSTR text;
int mInt;
};
for (int n = 0; n < lineCount - 1; ++n) {
vector<lines> sub;
lines lineData;
LPCSTR onlinePlayerName = (LPCSTR)PLAYER::GET_PLAYER_NAME((Player)(n));
int onlinePlayerPed = PLAYER::GET_PLAYER_PED(n);
//lines(n) = struct( onlinePlayerName, onlinePlayerPed );
sub.push_back(lines());
lineData.text = onlinePlayerName;
lineData.mInt = onlinePlayerPed;
//add struct to struct list
sub.push_back(lineData);
}
但是当我尝试从
线路调用时
lines[i].text
我得到 "Error: Type name is not allowed"。
这里的问题是您在类型上使用了 []
运算符。您将行声明为 struct
。
(这有助于保持 typenames
的大写字母,这样您就可以更轻松地区分它们。)
我想你是想打电话给 sub[i].text
。
所以我正在使用下面的代码,但在尝试从结构中的一行调用文本时遇到错误。
struct lines
{
LPCSTR text;
int mInt;
};
for (int n = 0; n < lineCount - 1; ++n) {
vector<lines> sub;
lines lineData;
LPCSTR onlinePlayerName = (LPCSTR)PLAYER::GET_PLAYER_NAME((Player)(n));
int onlinePlayerPed = PLAYER::GET_PLAYER_PED(n);
//lines(n) = struct( onlinePlayerName, onlinePlayerPed );
sub.push_back(lines());
lineData.text = onlinePlayerName;
lineData.mInt = onlinePlayerPed;
//add struct to struct list
sub.push_back(lineData);
}
但是当我尝试从
线路调用时lines[i].text
我得到 "Error: Type name is not allowed"。
这里的问题是您在类型上使用了 []
运算符。您将行声明为 struct
。
(这有助于保持 typenames
的大写字母,这样您就可以更轻松地区分它们。)
我想你是想打电话给 sub[i].text
。