2012-02-26 16 views
1

ヘッドファイル内のシングルトンでエラーをコンパイル:私はグーグルしようとした私がコメント2でが、これは私のクラスである

expected unqualified-id at end of input 
コメント1で

expected ‘;’ before ‘*’ token 

を取得

#ifndef POINTPOOL_H_ 
#define POINTPOOL_H_ 

#include <list> 
#include <iostream> 

#include "ofPoint.h" 

// adapted from https://gist.github.com/1124832 

class PointPool 
{ 
    private: 
     std::list<ofPoint*> resources; 
     static PointPool* instance; 

     PointPool() {}; 

    public: 
     ~PointPool() {};      // 1 
     static pointPool* getInstance()  // 2 
     { 
      if (instance == 0) 
      { 
       instance = new PointPool(); 
      } 
      return instance; 
     } 

     Resource* getPoint() 
     { 
      if (resources.empty()) 
      { 
       std::cout << "Creating new." << std::endl; 
       return new ofPoint(); 
      } 
      else 
      { 
       std::cout << "Reusing existing." << std::endl; 
       ofPoint* resource = resources.front(); 
       resources.pop_front(); 
       return resource; 
      } 
     } 

     void disposePoint(ofPoint* object) 
     { 
      object->x = 0; 
      object->y = 0; 
      object->z = 0; 
      resources.push_back(object); 
     } 
}; 

PointPool* PointPool::instance = 0; 

#endif /* POINTPOOL_H_ */ 

が、私はこのコンパイラのメッセージのエラーと私のコードの間のリンクをうまくいけない..

+0

シングルトン???????なぜ??????????????????? –

答えて

2

あなたはこれを変更する必要があります:

static pointPool* getInstance() 

この目的のために:あなたのコンストラクタとデストラクタ後

static PointPool* getInstance() 

セミコロンも不要です。また、Edが述べたように、PointPool :: instanceの定義はヘッダー内にあってはいけません。

+1

首都はいつもあなたを時々つかまえる - それは死刑だと思う! –

1

この行PointPool* PointPool::instance = 0;は.cppファイルに入れる必要があります。そうしないと、複数のコピーが作成されます。

1

あなたはまた、であるpointPool*にタイプミスがあります。これを修正すると、両方のエラーがクリアされるはずです。

関連する問題