M
mweltin
I have been looking in the archives and as of yet have not found an
answer to my problem.
Class B has four members, and class A is derived from class B. Class
A only adds one new member to class B.
Class A has '<', '>', '==' and '=' overloaded, as well as a copy
constructor. Class B only has the copy constructor and assignment
operator overloaded.
I create a vector of A objects, and stuff them with random values.
When I sort the vector of A objects only the member unique to the A
object changes.
For example say I have three A objects in a vector blah
blah[0] {one = 5 two = 0.8 three = 0.1 mysortvar = 1}
blah[1] {one = 2 two = 0.7 three = 0.2 mysortvar = 0}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
I expect
blah[0] {one = 2 two = 0.7 three = 0.2 mysortvar = 0}
blah[1] {one = 5 two = 0.8 three = 0.1 mysortvar = 1}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
but I get
blah[0] {one = 5 two = 0.8 three = 0.1 mysortvar = 0}
blah[1] {one = 2 two = 0.7 three = 0.2 mysortvar = 1}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
Note:ONLY THE mysortvar values change.
could someone clue me into what I'm doing wrong?
thank you,
Markus
answer to my problem.
Class B has four members, and class A is derived from class B. Class
A only adds one new member to class B.
Class A has '<', '>', '==' and '=' overloaded, as well as a copy
constructor. Class B only has the copy constructor and assignment
operator overloaded.
I create a vector of A objects, and stuff them with random values.
When I sort the vector of A objects only the member unique to the A
object changes.
For example say I have three A objects in a vector blah
blah[0] {one = 5 two = 0.8 three = 0.1 mysortvar = 1}
blah[1] {one = 2 two = 0.7 three = 0.2 mysortvar = 0}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
I expect
blah[0] {one = 2 two = 0.7 three = 0.2 mysortvar = 0}
blah[1] {one = 5 two = 0.8 three = 0.1 mysortvar = 1}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
but I get
blah[0] {one = 5 two = 0.8 three = 0.1 mysortvar = 0}
blah[1] {one = 2 two = 0.7 three = 0.2 mysortvar = 1}
blah[2] {one = 7 two = 0.6 three = 0.3 mysortvar = 3 }
Note:ONLY THE mysortvar values change.
could someone clue me into what I'm doing wrong?
thank you,
Markus