• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

multiple objects in a vector...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey i hope you can help me with this...,
I have a vector which contains several elements consisting of a user defined object. Now I'd like to add objects of ANOTHER user defined object. I know you can do this in C++, but can you also do this in java? My main question is once I add elements of this new objectt ype, how do I go through the vector element by element checking to see what type of object is stored in there. If I have the first user defined object in the slot, then I need to do a certain set of operations to it and if I have the 2nd user defined object in the slot then I need to do another set of operations to it....thanks for all the help!
amr
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
amr amr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help but it still hasnt answered my question...perhaps I wasnt clear...I want to know how exactly you check to see what type of object is stored in the element...in other words in those if statements in the code how do i determine if elm is an instance of class1 or class2....i hope this clarifies my question better...thanks again...
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by amr amr:
thanks for the help but it still hasnt answered my question...perhaps I wasnt clear...I want to know how exactly you check to see what type of object is stored in the element...in other words in those if statements in the code how do i determine if elm is an instance of class1 or class2....i hope this clarifies my question better...thanks again...



To check the type of an object use the instanceof operator, I guess you missed it up in Jean-Francois post.

Originally posted by Jean-Francois Briere:

// verify its class type
if (elm instanceof ClassName1)
{
ClassName1 elm1 = (ClassName1)elm;
...
}


[ March 28, 2004: Message edited by: Vicken Karaoghlanian ]
 
amr amr
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oh ok thanks, i thought it was pseudocode or something, i will try that...do i also need the elm before instane of that he has in the if statement
 
reply
    Bookmark Topic Watch Topic
  • New Topic