Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange compilation error with a template member method

Status
Not open for further replies.

globos

Programmer
Nov 8, 2000
260
FR
Hi all,

I get a compilation error with this source code (simplified to isolate the problem) :
Code:
struct VirtualTable
{
  template<typename _FUNC_>
  void add()
  {
  }
}; // struct VirtualTable

template<typename _T_>
struct functor
{
  private:
    VirtualTable* _vtable;
  public:
    functor(VirtualTable* vtable) :
      _vtable(vtable)
    {
    }

    template<typename _U_>
    void operator()(const _U_& /*v*/)
    {
      this->_vtable->add<_U_>(); // <- This is where the compiler complains
    }
}; // struct functor

int main()
{
  functor<int> func(0);
  return 0;
}

I get the following compilation errors at line "this->_vtable->add<_U_>()" :

main.cpp: In member function ‘void functor<_T_>::eek:perator()(const _U_&)’:
main.cpp:23: error: expected primary-expression before ‘>’ token
main.cpp:23: error: expected primary-expression before ‘)’ token

The version of gcc I used is 4.2.4.
Note that there is no error with the above code with Visual C++ 2008 (Express Edition).

What is the problem with gcc ?

--
Globos
 
Try this:
Code:
      this->_vtable->add<typename _U_>();
 
Code:
this->_vtable->add<typename _U_>();

This does not work, g++ outputs :
main.cpp: In member function ‘void functor<_T_>::eek:perator()(const _U_&)’:
main.cpp:23: error: expected nested-name-specifier before ‘_U_’
main.cpp:23: error: expected `(' before ‘_U_’
main.cpp:23: error: expected `;' before ‘_U_’


--
Globos
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top