Template syntax puzzle
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Template syntax puzzle

  1. #1
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,725

    Template syntax puzzle

    Has anyone got an idea what the correct syntax for this overloaded operator might be?

    This is what I thought would be OK, but it doesn't compile.

    Code:
    template <typename T>
    class MyTemplate
    {
    public:
        
        template <typename TIterator>
        void operator ()(TIterator first, const TIterator& last); 
    };
    
    template <typename T, typename TIterator>
    inline void MyTemplate<T>::operator ()(TIterator        first,
                                           const TIterator& last)
    {
    
    }
    Combining the declaration and definition in the class compiles fine, but there are compiler specific reasons why they must be separate. (It's to do with memory section directives)
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,323

    Re: Template syntax puzzle

    Wouldn't it be:
    Code:
    template <typename T>
    template <typename TIterator>
    inline void MyTemplate<T>::operator ()(TIterator        first,
                                           const TIterator& last)
    {
    
    }
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,725

    Re: Template syntax puzzle

    Yes, that works

    Seems perfectly logical now.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center