mardi 5 juillet 2016

C++ call templated method on vector iterator [duplicate]

I'm trying to access to a templated method from a vector iterator but I can't compile my code and I get through some error.

Here a sample of my code (without constructors, destructor, and all attributes and methods). However this code snippet reproduce the error I get.

#include <vector>
#include <boost/any.hpp>

class Value: public boost::any {
public:
  Value () :
      boost::any() {
  }

  template<typename dataT>
  Value (const dataT& value) :
      boost::any(value) {
  }

  template<typename dataT>
  dataT as () const {
    return boost::any_cast<dataT>(*this);
  }
};

class Src {
public:
  inline const Value& operator[] (const int& index) const {
    return _values[index];
  }

  inline Value& operator[] (const int& index) {
    return _values[index];
  }

  template<typename dataT>
  dataT getValue (const int& index) const {
    return operator[](index).as<dataT>();
  }

private:
    std::vector<Value> _values;
};

template<typename SRC>
class A{
public:
  template<typename dataT>
  std::vector<dataT> getValues (const size_t& attr_index) const {
    std::vector<dataT> data;

    typename std::vector<dataT>::iterator src;
    for (src = _data.begin(); src != _data.end(); ++src) {
      data.push_back(src->getValue<dataT>(attr_index));
    }

    return data;
  }
private:
  std::vector<SRC> _data;
};

Compilation error is the following one:

test.h: In member function ‘std::vector<dataT> A<SRC>::getValues(const size_t&) const’:
test.h:49:41: error: expected primary-expression before ‘>’ token
       data.push_back(src->getValue<dataT>(attr_index));

I have no idea of what happens here.

Have you any idea of what I'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire