C ++:错误"声明预期"

时间:2013-10-18 13:28:06

标签: c++ for-loop

我有以下cpp文件,并在此行中抛出错误“Declaration expected”,指向“for”:

for (int i = 0; i < m_Floats.size(); ++i) 

整个代码是:

#include "stdafx.h"
#include <vector>
#include "clsJenksBreaks.h"

using namespace std;

vector<float>m_Floats

vector<float>getJenksBreaks(const unsigned int uNumClass)
{
    //std::sort(m_Floats, m_Floats + size, std::greater<float>());

    float **mat1 = new float*[m_Floats.size()];
    for (int i = 0; i < m_Floats.size(); ++i) 
    {
        mat1[i] = new float[iNumClass];
    }
    for (unsigned long x=0;x<uNumClass+1;x++)
    {
        for (unsigned long y=0;y<m_Floats.size()+1,y++)
        {
            mat1[x][y]=0;
        }
    }

    //I have commented out the other code that is in this function, but the error still exists.

}

有人看到我哪里出错吗?

3 个答案:

答案 0 :(得分:9)

您指明的行没有错误。错误是:

  • 在第7行末尾缺少分号(m_Floats的声明)。
  • 缺少iNumClassuNumClass的声明(可能是他们在你没有向我们展示的标题中)
  • 逗号而不是第20行的分号,在for-loop incrementor之前。

答案 1 :(得分:4)

m_floats声明后,你错过了一个分号。尝试:

vector<float>m_Floats;

答案 2 :(得分:2)

可能的拼写错误,

 mat1[i] = new float[iNumClass];

应该是

 mat1[i] = new float[uNumClass];