2011-06-13 14 views
0

この問題は、Stroustrupのプログラミング原則とC++を使用したサンプルプログラムをコンパイルしようとしたときに発生しました。私は第12章でFLTKの使用を開始します。私は、グラフィックスとGUIのサポートコードでコンパイラのエラーを取得しています。具体的にGraph.hライン140および141は:引数リストなしのテンプレート名 'x'の無効な使用

error: invalid use of template-name 'Vector' without an argument list 
error: ISO C++ forbids declaration of 'parameter' with no type 


template<class T> class Vector_ref { 
    vector<T*> v; 
    vector<T*> owned; 
public: 
    Vector_ref() {} 
    Vector_ref(T& a) { push_back(a); } 
    Vector_ref(T& a, T& b); 
    Vector_ref(T& a, T& b, T& c); 
    Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0) 
    { 
     if (a) push_back(a); 
     if (b) push_back(b); 
     if (c) push_back(c); 
     if (d) push_back(d); 
    } 

    ~Vector_ref() { for (int i=0; i<owned.size(); ++i) delete owned[i]; } 

    void push_back(T& s) { v.push_back(&s); } 
    void push_back(T* p) { v.push_back(p); owned.push_back(p); } 

    T& operator[](int i) { return *v[i]; } 
    const T& operator[](int i) const { return *v[i]; } 

    int size() const { return v.size(); } 

private: // prevent copying 
    Vector_ref(const Vector&); <--- Line 140! 
    Vector_ref& operator=(const vector&); 
}; 

完全なヘッダーおよび関連グラフィックスのサポートコードはここで見つけることができます:
は、コードの修正に加えて http://www.stroustrup.com/Programming/Graphics/

、誰かが上のいくつかの光を当てるしてください可能性がありここでは普通の英語で何が起こっているのですか?私はちょうどテンプレートを勉強し始めたばかりなので、漠然としたアイデアがありますが、まだ手の届かないところです。おかげで百万、

答えて

7
Vector_ref(const Vector&); <--- Line 140! 

パラメータの型はVector_ref、ないVectorでなければなりません。タイプミスがあります。

Vector_ref& operator=(const vector&); 

ここでは、パラメータはvector<T>である必要があります。あなたは型引数について言及するのを忘れてしまった。

しかし、コメントを読んで、私はそれも誤植と考えています。 vector<T>のいずれかではありませんでした。あなたはこれらの意味:C++ 0xので

// prevent copying 
Vector_ref(const Vector_ref&); 
Vector_ref& operator=(const Vector_ref&); 

、あなたがコピーを防止するために、次のことが可能です。

// prevent copying 
Vector_ref(const Vector_ref&) = delete;   //disable copy ctor 
Vector_ref& operator=(const Vector_ref&) = delete; //disable copy assignment 
+0

うわー、ありがとうナワズ!あなたは熟知しています。とても感謝しております。 –