現在、C++ 11エイリアステンプレート(別名:template<class A> using B = C<A>;
)を使用していくつかのコードをリファクタリングしていますが、エイリアスを使用してコンストラクタを実装しようとするとオペレータ。C++でコンストラクタと演算子を呼び出す11エイリアステンプレート
関連するヘッダファイル:
template<class C>
class CSTree {
public:
class DepthIterator : public std::iterator<std::random_access_iterator_tag, C> {
DepthIterator(const DepthIterator&);
bool operator==(const DepthIterator&);
//other members omitted
}
//other members omitted
}
関連するソースファイル:つながらなかったインターネットを検索する
src/CSTree.cpp:13:10: error: nested name specifier 'DeIt<C>::' for declaration does not refer into a class, class template or class template partial specialization
src/CSTree.cpp:18:15: error: nested name specifier 'DeIt<C>::' for declaration does not refer into a class, class template or class template partial specialization
私の試み:
template<class C>
using DeIt = typename CSTree<C>::DepthIterator;
template<class C>
DeIt<C>::DepthIterator(const DepthIterator &rhs) { //Error here!
//...
}
template<class C>
bool DeIt<C>::operator== (const DepthIterator &rhs) { //Error here!
//...
}
打ち鳴らすでコンパイルするには、次のエラーを与えますこのトピックの明確な資料には、私はそれが実装可能かどうか疑問に思っています演算子とコンストラクタをエイリアステンプレートに追加してください。そうであれば、誤っている箇所に関するヒントがあれば大いに感謝します(私はC++にはまだまだ新しいので、本当に不愉快な間違いかもしれません)。その場合は事前に恩赦をお願いします)。
あなたの*現在の問題とは無関係ですが、*ソースファイル*にテンプレートクラスを実装していますか? ["なぜテンプレートはヘッダーファイルにのみ実装できますか?"](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header -file) –
ありがとう、私はそれについて知らなかった!それでも、私の実装を私の定義から切り離したいので、あなたがリンクした記事の中の1つの解決策を試してみましょう。 –