2010-11-27 14 views
0

私は、C++を使用したオプション価格についての書籍である "Financial Instrument Pricing Using 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

関連する問題