Firdous
Firdous

Reputation: 4652

Getting float values from a vector

I have little or no experience on C++ so question may sound wierd, the problem is that I have a std::vector containing float values, I want to extract float values from it by iterating it.

The definition code for the vector is like:

template <typename T, size_t feature_number>
  T vector_distance(const boost::array<T, feature_number>& v1,
                    const boost::array<T, feature_number>& v2);

  template <typename T = double, size_t feature_number=3>
  class CLASSNAME
  {
  public:
    typedef boost::array<T, feature_number> FeatureVector;
    typedef std::vector<FeatureVector> Features;
    ...

I am using it in the following way:

FeatureTypeDTW::Features mfcc_features_a = METHODTHATRETURNSVECTOR();

    for (int s = 0; s < (int) mfcc_features_a.size(); s++)
    {
        float MYFLOAT = mfcc_features_a[s];
    }

But the compile error that i get is:

No viable conversion from 'boost::array (float, 7)' to 'float'

Any hints for how to convert??

Upvotes: 1

Views: 1171

Answers (1)

Praetorian
Praetorian

Reputation: 109199

mfcc_features_a is of type Features, which is a vector of FeatureVectors; the latter is in turn an alias for boost::array<T, feature_number>.

In short, you're trying to assign a boost::array<T, feature_number> to a float. Now, assuming the template argument T for FeatureTypeDTW is a float (or something convertible to a floating point number) this should work.

float MYFLOAT = mfcc_features_a[s][0];  // assigns first element of boost::array
                                        // to MYFLOAT

Upvotes: 1

Related Questions