dimanche 27 janvier 2019

error C2131: expression did not evaluate to a constant - C++ VC 2017 [duplicate]

This question already has an answer here:

I have bellow code:

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();
}

But in this line int previous[ PROBLEM->ndata() ]; get me bellow error:

error C2131: expression did not evaluate to a constant

And say me failure was caused by non-constant arguments or reference to a non-constant symbol and note: see usage of 'PROBLEM'.

In my A.hh I declare like bellow:

ClusteringProblemPtr PROBLEM;

And in mock_ClusteringProblem.fwd.hh is like bellow:

#ifndef __MOCK_CLUSTERINGPROBLEM_FWD_HH__
#define __MOCK_CLUSTERINGPROBLEM_FWD_HH__

class ClusteringProblem;
typedef ClusteringProblem * ClusteringProblemPtr;

#endif 

What can I do?

(I am using from Microsoft Visual Studio 2017 - Version 15.9.6)

Aucun commentaire:

Enregistrer un commentaire