Sunday 15 June 2014

c++ - dereferencing iterator of STL set -


I have a problem inheriting from STL set (I think):

Here's the square Prime:

  Class Prime: Public Set & lt; A & gt; {Private: // Private Data Member Public: // C'tor ... void printParticularA (const & amp; id); }   

Here is the class A:

  Category A: Public listing & lt; B & gt; {Private: // data member int id; Public: // C'tor A (Constant & Copy): List & lt; B & gt; (Copy), // copy data member {// validate data and leave exceptions if necessary}; The Bull Operator & lt; (Constant A & RA) const {Return id & lt; Rhs.id; } Void printReport () const (for const & amp; item: * this) {item.print (); }}}   

Now this problem is in the next function, I want to print a particular object in the set:

  Zero Prime :: Print Particular A (Constant and ID) (Find (Episode) - & gt; Printport ();}   

I also tried to do this:

  Zero Prime :: Print Particular A (Consultant and ID) {* (Find (Episode (ID)). Print the Report ();}   

Note: Class b Rint () method.
Note 2: The preference is a class to create a dummy A object using only id data.

The problem is that when 'search' finds objects that it Const_iterator returns (because every object in the set is const), and when I dereference, I get a copy of the object (??), but the inside of the list is empty B.! - This is' - & gt; Version;

Now I know that the set is not allowed to change the objects. Gives, but I do not intend to change the object (as you can see in the announcement of printReport member function).

I appreciate any help in this!

EDIT: Thanks to everyone, you have helped me a lot in particular knowing what to do.
I solved the problem and this set was not in the list, nor was any of my classes presented here. Br> My mistake was to understand the question given to me (yes it is my homework assignment, I am still new to c ++). Sorry, if you think I was wasting my time.
I hope I can learn from all my experiences and help others someday! In short, thanks !! :)

Your code is very close and I do not see this problem tied directly or set to secondary. , But have completed the usual bad things

Get your session started for

Whatever will end your described problems, if not, then post a complete compiled example with the appropriate text of what you are looking for and what you expect.

No comments:

Post a Comment