Vectors using object pointers.

This is a discussion on Vectors using object pointers. within the C++ Programming forums, part of the General Programming Boards category; Hello. Currently I am working on a class that holds a vector of pointers to objects. Compiler errors in Visual ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    IL
    Posts
    23

    Vectors using object pointers.

    Hello. Currently I am working on a class that holds a vector of pointers to objects.

    Compiler errors in Visual Studio C++:
    Code:
    * cppsample\headers\Item.h(31): error C2065: 'ItemClass' : undeclared identifier
    * cppsample\headers\Item.h(31): error C2955: 'std::vector' : use of class template requires template argument list
    Here is the source for the headers involved:

    Item.h
    Code:
    #pragma once
    
    #include <string>
    #include <vector>
    #include "ItemClass.h"
    using namespace std;
    
    typedef short unsigned int sui;	//Shorthand form of numbers from 0 to 65,535.
    typedef short int si;			//Shorthand form of numbers from -32,768 to 32,767.
    
    class Item
    {
    public:
    	Item();
    	~Item();
    	//bool AddClass(ItemClass* cClass);
    	//bool RemoveClass(ItemClass* cClass,bool bDependantsToo);
    	string getName();
    	sui getMinAtt();
    	sui getMaxAtt();
    	sui getAtt();					//Random between min and max
    	sui getDef();
    	sui getAmt();
    	bool setAmt(sui newAmt);
    	sui getMaxAmt();
    	sui getHealth();
    	bool setHealth(sui newHealth);
    private:
    	string sName;
    	sui iAmount;
    	vector<ItemClass> cClasses;
    };
    ItemClass.h
    Code:
    #pragma once
    #include <string>
    #include "Item.h"
    using namespace std;
    //Classes
    class ItemClass
    {
    public:
    	friend class Item;
    	ItemClass(int minAttack=0,int maxAttack=0,int defense=0,string p="",string s="",ItemClass **apcAllowed=NULL,ItemClass **apcRequired=NULL,ItemClass **apcRestricted=NULL);
    	~ItemClass();
    private:
    	int minAtt;
    	int maxAtt;
    	int def;
    	string prefix;
    	string suffix;
    	
    	ItemClass** RequiredClasses;	//AND - All given classes must be present in given item for this class to be added
    	ItemClass** AllowedClasses;		//OR - At least one given class must be present in given item for this class to be added
    	ItemClass** RestrictedClasses;	//!OR - If any of these classes are present in the given item, this class cannot be added.
    };

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,318
    >> #include "Item.h"
    I don't see a reason to include that in ItemClass.h. It will lead to recursive includes. I think only a forward declaration is necessary there, so remove that line and add class Item; on a line before the ItemClass declaration.

    >> I am working on a class that holds a vector of pointers to objects.
    Where? The only vector I see holds ItemClass objects, not pointers. Not that there's anything wrong with that.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Location
    IL
    Posts
    23
    Thank you. I disabled the pointer thing because it was giving me additional compiler errors related to the original error, should have mentioned that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointers and vectors
    By larne in forum C Programming
    Replies: 6
    Last Post: 09-12-2008, 10:27 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. Replies: 60
    Last Post: 12-20-2005, 10:36 PM
  4. Really Hope I'm not Overposting (Object passing)
    By Shamino in forum Game Programming
    Replies: 10
    Last Post: 12-16-2005, 08:38 AM
  5. Replies: 2
    Last Post: 10-12-2002, 07:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21