LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 09-19-2015, 12:14 AM   #1
srinietrx
Member
 
Registered: May 2013
Posts: 101

Rep: Reputation: Disabled
Vector Implementation in C++


I am implementing vector as Assignment project.
Completed till now
1.Allocatating memory in constructor
2.Added element using push_back() and also written resize() to set size of reserved memory
3.Forward Iterator

Now I am designing revesre_iterator
using below
Code:
class reverse_iterator
{
    public:
    reverse_iterator(T *p)
    : pos(p) { }
 
    reverse_iterator()
    : pos(0) { }
 
    T &operator*()
    { return *pos; }
 
    T *operator->()
    { return pos; }
 
    reverse_iterator operator++(int)
    { pos--; return *this; }
 
    reverse_iterator operator--(int)
    { pos++; return *this; }
 
    bool operator!=(const reverse_iterator &rhs)
    { return this->pos != rhs.pos; }
 
    private:
    T *pos;
};
Not able to understand what is written inside reverse_iterator class particularly
this line
Code:
 T *operator->()
    { return pos; } .
I am new to STL but having knowledge of C++ and oops.
 
Old 09-19-2015, 07:47 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Umm... pardon me, but since YOU are designing the reverse_iterator class:

Quote:
Originally Posted by srinietrx View Post
Now I am designing revesre_iterator
Then how can you not...
Quote:
Originally Posted by srinietrx View Post
understand what is written inside reverse_iterator class particularly
this line
Code:
 T *operator->()
    { return pos; } .
I am new to STL but having knowledge of C++ and oops.
Furthermore, I wish I could help you with the code. I studied C++ at uni some 7-8 years ago, and learnt to hate it with a vengeance. I made a vow to never use that language for anything in the future, it has been an easy promise to keep ;-)

Best of luck!
HMW

Last edited by HMW; 09-19-2015 at 09:03 AM.
 
  


Reply



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
[SOLVED] vector,matrices drawing software. some thing like android(Visual Vector Math) PoleStar Linux - Newbie 3 11-02-2012 10:45 PM
LXer: Tropic of Vector – a blog devoted to Vector Linux Light, plus the Vector Linux LXer Syndicated Linux News 0 09-17-2009 01:30 PM
LXer: Vector Linux 5.9-Pseudo64-0.1 -- Finally, 64-bit Vector LXer Syndicated Linux News 0 09-12-2007 01:20 PM
Tripwire In Vector Linux 3.4 Or Its Implementation anil2003 VectorLinux 2 03-24-2006 06:32 PM
can i modify int 80 vector to a user-defined vector qqrilxk Linux - Security 1 03-03-2005 08:46 PM

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

All times are GMT -5. The time now is 03:19 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