Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Multiple objects from same class?  (Read 2364 times)

0 Members and 2 Guests are viewing this topic.

Jim70

  • Newbie
  • *
  • Posts: 23
    • View Profile
Multiple objects from same class?
« on: May 28, 2015, 10:03:42 am »
I have a basic ai system, how do i do it so that i dont have to re-write the code for every ai i add with the same functionality?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Multiple objects from same class?
« Reply #1 on: May 28, 2015, 10:08:24 am »
It's a very broad question (and not really related to SFML), can you be a bit more specifc?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jim70

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Multiple objects from same class?
« Reply #2 on: May 28, 2015, 10:11:21 am »
so that i can have one class (with sf::texture, sprite, private & public variables etc) and reference it more than once and display the on screen.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Multiple objects from same class?
« Reply #3 on: May 28, 2015, 10:14:17 am »
Use a container such as std::vector?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jim70

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Multiple objects from same class?
« Reply #4 on: May 28, 2015, 10:29:52 am »
isnt there something like  LOL lol = new LOL ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Multiple objects from same class?
« Reply #5 on: May 28, 2015, 10:32:10 am »
I think you should get a good C++ book and learn about classes and STL containers.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MakaiKing0

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Multiple objects from same class?
« Reply #6 on: May 28, 2015, 06:22:25 pm »
For once I agree with eXpl0it3r....

You should probably learn c++ before you try using it.  And your question is extremely broad, to the extent that it even extends to the programming model your using...  OOP, ECS, etc...  Your just going to have to figure out a model and run with it, then you can easily find a way to single out specific segments of your program such that it reduces or even erradicates redundancy....

GL

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Multiple objects from same class?
« Reply #7 on: May 28, 2015, 06:33:34 pm »
You can use virtual functions , or overloaded functions too, inclusive you can embed a script language such lua , python , ruby for the AI.. etc..

If the part of class/templates of c++ you don't know so well , buy a book (more recommendable) or google for tutorials.

http://www.cplusplus.com/files/tutorial.pdf
http://www.cprogramming.com/tutorial/c++-tutorial.html
http://www.cprogramming.com/tutorial/c++-tutorial.html

I would like a spanish/latin community...
Problems building for Android? Look here

 

anything