2016-04-27 9 views
0

私はクラスの外に私はそれが実現だ持って、私はフレンド関数の宣言、下を持っているテンプレートを、持っている:署名はテンプレートクラスのフレンド関数を呼び出すようにしようと

template<class TreeElement, class Comparator, class Operation> 
class AVLTree { 
public: 
    template<class A, class B, class C > 
    friend AVLTree<A, B, C> createEmptyAVLTree(int n); 
... 
} 
template<class A, class B, class C> 
AVLTree<A, B, C> createEmptyAVLTree(int n) { ... } 

は何ですかそれを他のファイルのどこかで呼び出すのですか?

私が試してみた:

AVLTree<Post, postByLikesFunc, emptyFunc>::createEmptyTree(); 
をそれはそれはそれを解決できませんでしたと言います。どうして ?友達のメンバーはちょうどそれのように見えるはずですね。

EDIT:

AVLTree<Post, postByLikesFunc, emptyFunc> empty; 
empty = createEmptyTreeAVLTree<Post, postByLikesFunc, emptyFunc>(size); 
empty.arrayToTree(sorted_posts); 

それの機能にTroll.cppにあります。

それでも「ファンクションが解決できなかった」、「このスコープ内で宣言されていなかった」、「シンボルが解決しないcouldntの」叫び「前のプライマリ・表現予想」、

+0

を解決しました。 Slardarが言ったように。 – KittyT2016

答えて

2

「>前に、プライマリ・表現予想」 AVL.hpp

#ifndef AVL_hpp 
#define AVL_hpp 

template<class T1, class T2, class T3> 
class AVLTree { 
public: 

    template<class A, class B, class C> 
    friend AVLTree<A, B, C> createEmptyAVLTree(int n); 
}; 

template<class A, class B, class C> 
AVLTree<A, B, C> createEmptyAVLTree(int n) { 
    return AVLTree<A,B,C>(); 
} 

#endif 

main.cppに

#include "AVL.hpp" 

int main() { 
    createEmptyAVLTree<int, int, int>(4); 
    return 0; 
} 

はcreateEmptyAVLTreeはAVLTreeの範囲内にありません。

+0

https://godbolt.org/g/h5CXHo –

+0

ok、他のファイルのmain?それは私が今やったことですが、他のファイルではまだ解決できませんでした。 – KittyT2016

+0

@ KittyT2016それも機能します。もっとコードを表示できますか? –

関連する問題