2010-11-27 7 views
0

C++를 사용한 옵션 가격 책에 대한 책인 "C++을 사용하는 금융 수단 가격 책정"의 일부 C++ 코드를 사용하고 있습니다. 다음 코드는 기본적으로 이름과 목록을 포함하도록 의도 된 SimplePropertySet 클래스를 정의하려는 많은 세부 사항을 제거한 작은 스 니펫입니다. VS2008에서이 코드를 컴파일에STL 클래스 용 반복자 함수 코딩

#include <iostream> 
#include <list> 
using namespace::std; 

template <class N, class V> class SimplePropertySet 
{ 
    private: 
    N name;  // The name of the set 
    list<V> sl; 

    public: 
    typedef typename list<V>::iterator iterator; 
    typedef typename list<V>::const_iterator const_iterator; 

    SimplePropertySet();  // Default constructor 
    virtual ~SimplePropertySet(); // Destructor 

    iterator Begin();   // Return iterator at begin of composite 
    const_iterator Begin() const;// Return const iterator at begin of composite 
}; 
template <class N, class V> 
SimplePropertySet<N,V>::SimplePropertySet() 
{ //Default Constructor 
} 

template <class N, class V> 
SimplePropertySet<N,V>::~SimplePropertySet() 
{ // Destructor 
} 
// Iterator functions 
template <class N, class V> 
SimplePropertySet<N,V>::iterator SimplePropertySet<N,V>::Begin()//<--this line gives error 
{ // Return iterator at begin of composite 
    return sl.begin(); 
} 

int main(){ 
    return(0);//Just a dummy line to see if the code would compile 
} 

, 나는 다음과 같은 오류를 얻을 :

warning C4346: 'SimplePropertySet::iterator' : dependent name is not a type 
    prefix with 'typename' to indicate a type 
error C2143: syntax error : missing ';' before 'SimplePropertySet::Begin' 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

뭔가 내가 잘못 가져 오거나 여기 잊고 오전 바보 또는 기본이 있습니까? 구문 오류입니까? 나는 그것에 손가락을 넣을 수 없다. 이 코드 스 니펫을 가져온 책은 Visual Studio 6에서 코드가 컴파일되었다고 말합니다. 버전 관련 문제입니까?

감사합니다. 컴파일러에 의해 나타난 바와 같이

답변

2

, 당신은 교체해야합니다

template <class N, class V> 
SimplePropertySet<N,V>::iterator SimplePropertySet<N,V>::Begin() 

로 :

template <class N, class V> 
typename SimplePropertySet<N,V>::iterator SimplePropertySet<N,V>::Begin() 

의존 이름에 대한 설명은 this link를 참조하십시오.

+0

아 ... 그 간단한 ... 정확한 방향으로 나를 가리켜 주셔서 감사합니다, 내 바보 같은 질문. 당신의 제안은 잘 돌아갔다. 고마워. – Tryer