Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

a class question

Ask ALL your questions here

a class question

Postby Ruddie on Thu Oct 22, 2009 6:09 am

okay, so I'm trying to make an RTS game in allegro, it's kinda hard. But I'm making great progress.

Now I'm wondering if it's possible do to something like this:

Class Destroyer
{
//blah blah
}

and then make x an int so that I can call it up by doing something like this..
Destroyer.1

but when I created it, I used this:

Destroyer.x (x = 1 at the moment I'm doing this)

Well, now I'm wondering, is this possible? Or is it just impossible

If this is working it will be great, because then I'm able to create alot of units on the game ;P


Friendly Regards, Ruud
Last edited by Ruddie on Thu Oct 22, 2009 10:22 am, edited 2 times in total.
Cheese tastes good!
User avatar
Ruddie
 
Posts: 36
Joined: Tue Sep 22, 2009 3:56 pm
Location: Netherlands

Re: a class question

Postby noobgrammer on Thu Oct 22, 2009 7:16 am

I don't think that is possible what your doing. I think want you want is a object array and that you can do
I need a compiler with a can of RAID built into it

I added a msn messenger just for programming feel free to email or add yourself to it
User avatar
noobgrammer
 
Posts: 198
Joined: Tue Aug 25, 2009 10:44 am
Location: Orlando

Re: a class question

Postby Ruddie on Thu Oct 22, 2009 10:12 am

noobgrammer wrote:I don't think that is possible what your doing. I think want you want is a object array and that you can do


Sorry, I think I explained it kinda stupid.
I meant something like this:

Class Destroyer
{
//blahblah
}

Destroyer.x;

and then I want that x to be a number, so instead of calling up x.Destroyer to change things, I want to be able to do: Destroyer.1if x was 1 at the moment of creation.
Cheese tastes good!
User avatar
Ruddie
 
Posts: 36
Joined: Tue Sep 22, 2009 3:56 pm
Location: Netherlands

Re: a class question

Postby Moosader on Thu Oct 22, 2009 11:38 pm

Provided that x is public, you can be like

Destroyer.x += Destroyer.speed;

but in general, you'll want to write a function to do this for you, so

Destroyer.Move( UP );

would take care of the code.


I don't really understand what "Destroyer.1" means.

For having multiple units, you'd have multiple instances, using either a static array:

Destroyer destroyerUnit[100];

or a dynamic array:

Destroyer *destroyerUnit = NULL;
destroyerUnit = new Destroyer[SIZE];

but make sure you clean up your code.


You can set default variable values with constructors.
User avatar
Moosader
 
Posts: 25
Joined: Mon Jul 06, 2009 5:31 pm
Location: Kansas City


Return to QA

Who is online

Users browsing this forum: No registered users and 0 guests