LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   vector<T>::iterator return type (https://www.linuxquestions.org/questions/programming-9/vector-t-iterator-return-type-857865/)

gothrog 01-21-2011 03:55 PM

vector<T>::iterator return type
 
Hi,

I'm trying to write some code that involves creating a function to return a vector iterator.

I'm not sure what is wrong.

Code:

template <typename T> class VectorTemplate
{
  public:

      VectorTemplate()
      {
        pthread_mutex_init(&m_tLock, NULL);
        pthread_cond_init(&m_ReadyEvent, NULL);
              m_maxVectorSize = DEFAULT_VECTOR_SIZE;
        testStr = "Test Hello";
      }

......................

      vector<T>::iterator getBegin()
      {
        return m_theVector.begin();
      }

Error:
Code:

VectorTemplate.h:140: error: type ?std::vector<T, std::allocator<_CharT> >? is not derived from type ?VectorTemplate<T>?
VectorTemplate.h:140: error: expected ?;? before ?getBegin?

Mike

savotije 01-21-2011 07:04 PM

What is declaration of m_theVector?

ta0kira 01-21-2011 11:42 PM

First of all, you need typename before vector<T>::iterator. The error occurs before the function body is even looked at, so this might be your only problem.
Kevin Barry

gothrog 01-22-2011 05:06 PM

savotije - it is a vector.
ta0kira - I thought that it just needs to be in the class to use the typename T already stated.

Code:

template <typename T> class VectorTemplate
{
  public:

      VectorTemplate()
      {
        pthread_mutex_init(&m_tLock, NULL);
        pthread_cond_init(&m_ReadyEvent, NULL);
              m_maxVectorSize = DEFAULT_VECTOR_SIZE;
        testStr = "Test Hello";
      }

......................

      vector<T>::iterator getBegin()
      {
        return m_theVector.begin();
      }

......................

  private:

      // The actual vector
      vector<T>      m_theVector;

......................

};


gothrog 01-22-2011 06:17 PM

ta0kira - thanks, I should have taken that more literally.

Fixed:
typename vector<T>::iterator getBegin()


All times are GMT -5. The time now is 12:33 PM.