2016-04-16 9 views
-5

スタックオーバーフローが発生しました。ここで')'トークンの前にunqualified-idエラーが発生しました

In file included from graph.h:97:0, 
        from main.cpp:2: 
    graph.hpp:4:26: error: expected unqualified-id before ‘)’ token 
    typename graph<T>::graph(){ 
         ^
makefile:2: recipe for target 'executable.x' failed 

これまでのところ、私のgraph.hppファイルです:私は、テンプレートのグラフのクラスを作成し、graph.hとgraph.hpp二つのファイルに分割しているが、毎回私はこのエラーを取得するコンパイルすると思います

#include "graph.h" 

//template <typename T> 
typename graph<T>::graph(){ 
    numVertices = 0; 
    graphWeight = 0; 
} 

そして、私のgraph.hファイルは次のようになります:

template <typename T> 
class graph{ 

    public: 
     graph(); 
. 
. 
. 
    private: 



}; 

また、私のmain.cppには、単純に次のとおりです。

#include "graph.h" 

int main(){ 
    graph<int> g; 

} 

何かが間違っている可能性がありますか?私はおそらくそれはテンプレートと関係がある単純なものだと分かっています。

おかげで、あなたのgraph.hppスニペットで

+1

をコメント解除してください.'テンプレート 'のコメントを外し、その後に続く' typename'を削除してください。 –

答えて

0

、残念ながら、この

#include "graph.h" 

template <typename T> 
graph<T>::graph(){ //Constructor has no return type. 
    numVertices = 0; 
    graphWeight = 0; 
} 

にあなたのコードを変更し、あなたは本当に、テンプレート用に別のヘッダーと実装ファイルを持っているので、あなたのヘッダーでの実装を置くことができないしていますファイル。詳細と回避策については、Why can templates only be implemented in the header file?

+0

ありがとう!それを調べます! –

関連する問題