だから私はこの問題を抱えています。
基本的に、テンプレート化されたインターフェースがあります:
template <typename T, typename U>
class Iinterface
{
public:
virtual ~Iinterface()
// A pure methode for the example that gives me the problem
virtual std::vector<T> myMethod(T, U) = 0;
};
今のところ問題ありません。そこで、このインターフェースから継承するクラスを宣言します。
class firstclass : public Iinterface<std::string, int>
{
// content doesnt matter. The problem is in second class inheritance.
// here I just put the class so we can see how I inherited in 1st class.
};
これで、cpp ファイルに myMethod 宣言が追加されました。
template <>
std::vector<std::string> firstClass::iInterface<std::string, int>::myMethod(std::string a, int b)
{
// methods code
}
これまでのところ、問題はありません。myMethod 関数を宣言する 2 番目のクラスであり、型 T が戻り値と同じであるため、コンパイル エラーが発生します。
class secondClass : public IInterface<std::vector<std::string>, int>
{
// class content
};
現時点ではコンパイルされますが、次のように myMethod を宣言すると:
template <>
std::vector<std::string> secondClass::Iinterface<std::vector<std::string> a, int n>
{
// methodes code
}
ここで、std::vector の戻り値とメソッドの引数でエラーが発生します。テンプレートの競合だと思いますが、これを回避する方法が本当にわかりません。
最初のエラー:
28 :template-id ‘_out<>’ for ‘std::vector<std::basic_string<char> > Iio<std::vector<std::basic_string<char> >, int>::_out(std::vector<std::basic_string<char> >, int)’ does not match any template declaration
2 番目のエラー:
28 note: saw 1 ‘template<>’, need 2 for specializing a member function template
私はまだ C++ でコーディングする方法を学んでいて、すぐに習得できますが、時々行き詰まり、助けが必要になります。私がこれをやろうとしている方法は間違っていますか?この競合を回避するには、3 番目の型名を宣言する必要がありますか? (2つのタイプが同じタイプであるため、別の競合が発生すると考えていました)。
私がやろうとしていることは、これを行うための最良の方法ではないかもしれないことを知っていますが、私はまだ学んでいます.
詳細が必要な場合は、お気軽にお問い合わせください。
すべてのヘルプは非常に高く評価されます。ありがとう。