错误C2131:表达式未求值为常数-C ++ VC 2017

时间:2019-01-27 07:23:32

标签: c++ c++11 visual-c++ c++17

我有以下代码:

Clustering::Clustering( VectorIntPtr locus_encoding ){
    // Allocate memory and initialise
    _cluster_assignment = allocate_VectorInt( PROBLEM->ndata() );
    for( int i=0; i<PROBLEM->ndata(); i++ ){ _cluster_assignment[ i ] = -1; }
    _total_clusters = 0; // Total number of clusters found  
    int previous[ PROBLEM->ndata() ];
    // Get assinment of each data element to a cluster
    // Each connected component of the graph (as encoded in the adjacency-base encoding)
    // represents a different cluster
    for( int i=0; i<PROBLEM->ndata(); i++ ){
        int ctr = 0; 
        // Unassigned element found, assign cluster
        if( _cluster_assignment[ i ] == -1 ){
            // Assign to cluster, keep track of it, 
            // and identify neighbour (adjacent element)
            _cluster_assignment[ i ] = _total_clusters;
            previous[ ctr++ ] = i;
            int neighbour = locus_encoding[ i ]; 
            // Repeat operation for consecutive neighboring elements
            // and assign to the same cluster
            while( _cluster_assignment[ neighbour ] == -1 ){
                _cluster_assignment[ neighbour ] = _total_clusters;
                previous[ ctr++ ] = neighbour;
                neighbour = locus_encoding[ neighbour ]; 
            }      
            // If a previously assigned neighbour is reached,
            // and this element was assigned to a different cluster X, 
            // re-assign all elements in 'previous' list to cluster X
            if( _cluster_assignment[ neighbour ] != _total_clusters ){
                while( --ctr >= 0 ){
                    _cluster_assignment[ previous[ ctr ] ] = _cluster_assignment[ neighbour ]; 
                }
            }else{
                // Increase cluster counter
                _total_clusters++;
            }
        }       
    }
    // Centroid computation
    compute_cluster_centres();
}

但是在这一行int previous[ PROBLEM->ndata() ];中,我得到了下面的错误:

error C2131: expression did not evaluate to a constant

说我失败是由非恒定参数或对非恒定符号的引用引起的,请注意:请参阅“问题”的用法。

在我的A.hh中,我像下面这样宣布:

ClusteringProblemPtr PROBLEM;

mock_ClusteringProblem.fwd.hh中就像下面这样:

#ifndef __MOCK_CLUSTERINGPROBLEM_FWD_HH__
#define __MOCK_CLUSTERINGPROBLEM_FWD_HH__

class ClusteringProblem;
typedef ClusteringProblem * ClusteringProblemPtr;

#endif 

我该怎么办?

(我正在使用Microsoft Visual Studio 2017-版本15.9.6)

0 个答案:

没有答案