Advertisement

Classes and Inventory?

Started by July 14, 2000 01:51 PM
10 comments, last by Goblin 24 years, 5 months ago
CItem is just the name of a class i made up (simply defined in one of the posts above). It was my idea for an abstract base class (a class that is useless on its own, but is defined as a template for inheritance). All your other object classes would inherit from this (gives you a common base for all your different types of items).

The definition:
        CItem **m_inventory;[/source]basically declares a variable m_inventory to be a pointer to a pointer. You can use that to declare an array of pointers to instances of CItem.You could have equally done this (example 1):[source]CItem *m_inventory[50];[/source]which declares an array of pointers to instances of class CItem.This locks you into having an array of 50 items (for example). Where as the original example (example 2) eg:[source]int     m_maxItems = 30;CItem **m_inventory;m_inventory = new CItem*[m_maxItems];    


allows you to dynamically allocate as many items you wish for a single entity. Ie if some Entities cannot carry any objects, there's no need to allocate memory for it (a saving) whereas with example 1, you will always have allocated 50 pointers for every Entity whether you need less or more.

I dont mean this nastily, but i think you should have a read of some books on object orientated programming and C++. They can explain more than i can write here.


Edited by - shamen on July 18, 2000 10:20:59 AM
D''oh! Sorry to seem so stupid, but when I said:
quote:
And also what an item in means? I''ve never really seen it before, so it strikes me as odd...

... I had just made a stupid grammer mistake. I wasn''t asking about the CItem class, but I meant to be asking about stuff inside those kind of tag-brackets... never seen it before.

Hehe, sorry about the confusion.

- Goblin
"A woodchuck would chuck as much wood as a woodchuck could if a woodchuck could chuck wood. Deal."
- The Goblin (madgob@aol.com)

This topic is closed to new replies.

Advertisement