0

So I have an abstract class named "User" and two derivated classes named "Seller" and "Buyer". I also have a vector of users in which I push sellers and buyers... My question is: if I get a random element from vector, how can I know if the element it's seller or buyer? Thanks

Marius
  • 13
  • 4
  • 1
    The more interesting question is: why do you have to know? Your classes themselves should know what to do. But if you want to stick to a broken design try `instanceof`. – Timothy Truckle Nov 06 '16 at 11:30
  • Any need to know what specific subtype of a parent class you are looking at is serious code smell. Rethink your logic. – Boris the Spider Nov 06 '16 at 11:32

1 Answers1

0

use isInstanceOf(Object); on the random object with an if() condition to check if it' a a buyer or a seller

Osama Salama
  • 647
  • 1
  • 8
  • 17