CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2007
    Posts
    34

    [RESOLVED] Enum in template class

    Can anyone help with the cause and resolution to this compile error?

    Here is the code:
    Code:
        template <typename T>
        class BigQueue {
        public:
            enum QueueState {GOOD, BAD, UNKNOWN};
        
        ....
    
        private:
            QueueState getQueueState();
    
        ....
        };
    
    
        template <typename T>
        QueueState BigQueue<T>::getQueueState()
        {
            return m_queueState;
        }
    This is not the complete code. I tried to pull out only the parts that pretain to the compile error. Also, all of this is in the .h file. Using gcc on Linux. If more information is needed please let me know.

    Here is the compile error:
    error: expected constructor, destructor, or type conversion before "BigQueue"

    I read about undeducible context having to do with this compile error but I really did not understand exactly what that means and how to fix it. Something to do with returning the enum type from a function that is part of the template class.

    Will someone please help with what is going on?

    Thanks.
    Last edited by Yadrif; July 16th, 2009 at 10:53 AM.

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

    Re: Enum in template class

    QueueState is defined within the BigQueue class template, so you cannot use it as a return type when that context cannot be deduced with qualification. As such, you should write:
    Code:
    template <typename T>
    typename BigQueue<T>::QueueState BigQueue<T>::getQueueState()
    {
        return m_queueState;
    }
    I assume that the declaration of m_queueState was replaced by "....".
    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

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured