How to deduce template argument implicitly?

Discussion in 'C++' started by Nephi Immortal, Jan 26, 2013.

  1. I already explicitly defined X< 1 > x since argument explicitly exists. I do not want to tell the Compiler to deduce the template argument in Test() function, but it should be done implicitly.

    error C2783: 'void Test(const X<T>::Y &)' : could not deduce template argument for 'T'

    template< int T >
    class X
    {
    private:
    class Y
    {
    public:
    Y() {}
    ~Y() {}

    void Do() const {}
    };

    template< int T >
    friend void Test( typename const X< T >::Y& ref );

    public:
    X() {}
    ~X() {}

    Y Go() { return Y(); }
    };

    template< int T >
    void Test( typename const X< T >::Y& ref )
    {
    ref.Do();
    }


    int main()
    {
    X< 1 > x;

    Test< 1 >( x.Go() ); // OK
    // Test( x.Go() ); // error C2783: 'void Test(const X<T>::Y &)' : could not deduce template argument for 'T'

    return 0;
    }
    Nephi Immortal, Jan 26, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    535
  2. George2

    template function argument deduce

    George2, Mar 11, 2008, in forum: C Programming
    Replies:
    0
    Views:
    369
    George2
    Mar 11, 2008
  3. Ed
    Replies:
    1
    Views:
    392
    James Kanze
    Aug 14, 2008
  4. Maik
    Replies:
    2
    Views:
    991
  5. nguillot
    Replies:
    5
    Views:
    530
Loading...

Share This Page