I have a classe called Nuage
with the implementation:
nuage.hpp
using namespace std;
template <typename T>
class Nuage {
private:
vector<T> v;
static vector<T>::const_iterator it;
public:
Nuage();
void ajouter(T);
int size();
T& begin();
~Nuage();
};
nuage.cpp
template <typename T>
Nuage<T>::Nuage(){}
template <typename T>
void Nuage<T>::ajouter(T p) {
v.push_back(p);
}
template <typename T>
int Nuage<T>::size() {
return v.size();
}
template <typename T>
T& Nuage<T>::begin(){
return v.begin();
}
template <typename T>
Nuage<T>::~Nuage(){}
When i try to test the functioning of the class from a separate file, there are two errors with the following line of the code: The following line is from a unit test that I can't change, so my code should adapt to it. Nuage::const_iterator it = n.begin();
The unit test code is:
TEST_CASE ( "TP2_Nuage::Iterateurs" ) {
Polaire p1(12,34);
Polaire p2(56,78);
Polaire p3(90,12);
Polaire p4(34,56);
Nuage<Polaire> n;
n.ajouter(p1);
n.ajouter(p2);
n.ajouter(p3);
n.ajouter(p4);
Polaire t[4];
unsigned i = 0;
Nuage<Polaire>::const_iterator it = n.begin();
while (it!=n.end()) t[i++]=*(it++);
REQUIRE ( t[0].getAngle() == Approx(p1.getAngle()) );
REQUIRE ( t[0].getDistance() == Approx(p1.getDistance()) );
REQUIRE ( t[1].getAngle() == Approx(p2.getAngle()) );
REQUIRE ( t[1].getDistance() == Approx(p2.getDistance()) );
REQUIRE ( t[2].getAngle() == Approx(p3.getAngle()) );
REQUIRE ( t[2].getDistance() == Approx(p3.getDistance()) );
REQUIRE ( t[3].getAngle() == Approx(p4.getAngle()) );
REQUIRE ( t[3].getDistance() == Approx(p4.getDistance()) );
}
The errors are:
error: need ‘typename’ before ‘std::vector<T>::const_iterator’ because ‘std::vector<T>’ is a dependent scope
error: ‘const_iterator’ is not a member of ‘Nuage<Polaire>’
Nuage<Polaire>::const_iterator it = n.begin()