내가 템플릿을 사용하여 C++ 표준 라이브러리의 벡터 클래스를 캡슐화하기 위해 노력하고있어하지만 난이 오류가 계속이C++ 템플릿 래퍼 클래스 : 벡터
SceneVector.h: In member function ‘void scenegraph::SceneVector<V>::print()’:
SceneVector.h:40: error: expected ‘;’ before ‘it’
SceneVector.h:40: error: ‘it’ was not declared in this scope
내가 만들어 관리했습니다 코드는
입니다#include <map>
#include <vector>
#include <iostream>
namespace scenegraph
{
template <class V> class SceneVector
{
typedef std::vector<V> Vector;
Vector vector;
public:
SceneVector();
void insert(const V value);
void print();
};
template <class V> SceneVector<V>::SceneVector()
{
vector.clear();
}
template <class V> void SceneVector<V>::insert(const V value)
{
vector.push_back(value);
}
template <class V> void SceneVector<V>::print()
{
for(Vector::iterator it = vector.begin(); it != vector.end(); ++it)
{
std::cout << "[" << (*it) << "] " << std::endl;
}
std::cout << std::endl;
}
}
누구든지 나를 교정 할 수 있습니까? 내가 C++ 초보자이기 때문에 답이 매우 사소할 수도 있습니다.
또 하나 ... 'typename'이 필요합니다. http://stackoverflow.com/q/1123080/51831 – jpalecek
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.21 – ephemient