LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2011, 03:55 PM   #1
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Rep: Reputation: 15
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

Last edited by gothrog; 01-21-2011 at 03:57 PM.
 
Old 01-21-2011, 07:04 PM   #2
savotije
Member
 
Registered: Oct 2010
Location: Serbia (Europe)
Distribution: Slackware 13.1
Posts: 97

Rep: Reputation: 6
What is declaration of m_theVector?
 
Old 01-21-2011, 11:42 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
1 members found this post helpful.
Old 01-22-2011, 05:06 PM   #4
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Original Poster
Rep: Reputation: 15
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;

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

};
 
Old 01-22-2011, 06:17 PM   #5
gothrog
Member
 
Registered: Jun 2004
Distribution: Yellow Dog, Fedora, RedHat, Centos, Ubuntu, Suse Linux
Posts: 106

Original Poster
Rep: Reputation: 15
ta0kira - thanks, I should have taken that more literally.

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
error: new types may not be defined in a return type Kenny_Strawn Programming 4 10-13-2010 12:21 AM
c++, linux, Do STL map iterator always return in same order when iterate from begin( linux_linux Linux - Newbie 7 03-15-2008 08:56 PM
PHP return type error bahadur Programming 0 08-11-2006 04:37 AM
C++ return type ashirazi Programming 4 09-19-2004 03:01 PM
constructor return type macro-linux Programming 2 11-12-2003 01:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration