Jump to content

Confusing Templating Problems

- - - - -

  • Please log in to reply
3 replies to this topic

#1
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Edit: Sorry, someone on IRC has answered my question. I'll leave the problem code below though. The solution is in the second post in this thread.

template<class T>
struct A
{
    template<class Value>
    void foo() { }
};

template<class T>
void bar()
{
    A<T> i;

    // error: expected primary-expression before ‘>’ token
    // error: expected primary-expression before ‘)’ token
    i.foo<T>();
}

template<class T>
void qux()
{
    A<int> i;

    // No error
    i.foo<T>();
}

int main()
{
    return 0;
}

Edited by brownhead, 06 January 2011 - 11:35 AM.


#2
ambidextrous

ambidextrous

    Newbie

  • Members
  • Pip
  • 4 posts
Could you let us all know what the solution was? Thanks!
Codito ergo sum :loading:

#3
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
I've actually written a very detailed description of the problem and solution in my blog. However, if you're just interested in the quick solution below is the fixed code. I will repaste the problem code back into the original post as well.
template<class T>
struct A
{
    template<class Value>
    void foo() { }
};

template<class T>
void bar()
{
    A<T> i;

    i.template foo<T>();
}

template<class T>
void qux()
{
    A<int> i;

    i.foo<T>();
}

int main()
{
    return 0;
}


#4
ambidextrous

ambidextrous

    Newbie

  • Members
  • Pip
  • 4 posts
Awesome, thanks!
Codito ergo sum :loading:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users