0

今日、テンプレート化されたクラスのテンプレート化されたメソッドを呼び出したい場合は、またはのtemplate keyword後に使用する必要があることがわかりました。このような:.->

template <class T>
class Foo 
{
    public:
    template <class I>
    void templatedMethod() {};
};

template<typename T, typename I>
void oops() {
    Foo<T>().template templatedMethod<I>(); // error without template kw
}

int main()
{
    oops<double, int>();
}

私の問題は、この templatedMethod が私の公開 API の一部であり、ユーザーに入力させたくないというtemplateことです。これはそれほど定期的ではなく、潜在的なユーザーを落胆させる可能性があるためです。

私の質問は次のtemplatedMethodようなものに名前を変更してから_templatedMethod、同じヘッダーファイルで提供することをお勧めしますmacro #define templatedMethod template _templatedMethod?

ユーザーは通常それを呼び出すことができます:

Foo<T> f;
f.templatedMethod<I>();

何が問題になる可能性がありますか?この問題は通常どのように解決されますか? ありがとうございました。

4

0 に答える 0