gpt4 book ai didi

c++ - 警告 : statement has no effect (C++)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:56:12 24 4
gpt4 key购买 nike

我有以下代码:

void CScriptTable::EnumReferences(asIScriptEngine *engine)
{
if (m_table)
{
// Call the gc enum callback for each nested table
size_t col = 0, row = 0, num_cols = m_table->numCols(), num_rows = m_table->numRows();

for( col; col < num_cols; col++ ) // Line 92
{
if (m_table->getColType(col) == COL_TABLE) {
for (row; row < num_rows; row++){ // Line 95
Table * tbl = m_table->getTable(row, col);
engine->GCEnumCallback(tbl);
}
}
}
}
}

编译 (g++) 时,第 92 和 95 行发出警告(语句无效)(在上面的代码片段中指示)

我不明白为什么他们没有效果,即使我已经盯着它看了一会儿 - 可以用第二双眼睛看看他们是否能发现我错过的东西。

最佳答案

如果您猜想遍历所有列,并针对所有行遍历每一列。所以最好把你的代码改成这样:

for 循环中的第一条语句执行一次,即在第一次进入循环时。由于您想为所有其他列包含行号零,因此您必须为每一列将行设置为 0:

void CScriptTable::EnumReferences(asIScriptEngine *engine)
{
if (m_table)
{
// Call the gc enum callback for each nested table
size_t num_cols = m_table->numCols(), num_rows = m_table->numRows();

for(size_t col = 0; col < num_cols; col++ ) // Line 92
{
if (m_table->getColType(col) == COL_TABLE) {
for (size_t row = 0; row < num_rows; row++){ // Line 95
Table * tbl = m_table->getTable(row, col);
engine->GCEnumCallback(tbl);
}
}
}
}
}

关于c++ - 警告 : statement has no effect (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7951662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com