template and nested class problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Miroslav Novak

    template and nested class problem

    Hi,
    I can't compile the following code. Does anyone know where is the problem?
    Thank you in advance,
    Mirek.

    code:
    ----------------

    template<class T>
    struct CA
    {
    struct CB
    {
    T* z;
    };
    };

    template<class T>
    void fun(typename CA<T>::CB x) {}; // line 56

    void test()
    {
    CA<int>::CB x;
    fun(x); // line 61
    }

    errors:
    ------------

    test.cpp(61) : error C2783: 'void fun(CA<T>::CB)' : could not deduce
    template argument for 'T'
    test.cpp(56) : see declaration of 'fun'



  • Gianni Mariani

    #2
    Re: template and nested class problem

    Miroslav Novak wrote:[color=blue]
    > Hi,
    > I can't compile the following code. Does anyone know where is the problem?
    > Thank you in advance,
    > Mirek.
    >[/color]
    ....[color=blue]
    > errors:
    > ------------
    >
    > test.cpp(61) : error C2783: 'void fun(CA<T>::CB)' : could not deduce
    > template argument for 'T'
    > test.cpp(56) : see declaration of 'fun'
    >[/color]

    That's correct. It will not deduce T in this case.

    Comment

    • Fraser Ross

      #3
      Re: template and nested class problem

      Template parameter T of struct CA cannot be deduced from a nested template
      class parameter. Presumably anyway. It is logical to me. Explicitly call
      fun with <int>.

      Fraser.


      ---
      Outgoing mail is certified Virus Free.
      Checked by AVG anti-virus system (http://www.grisoft.com).
      Version: 6.0.532 / Virus Database: 326 - Release Date: 27/10/2003


      Comment

      Working...