C++ inventory

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

91 Replies - 3162 Views - Last Post: 28 January 2013 - 12:14 AM Rate Topic: -----

#31 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 24 January 2013 - 07:29 PM

main.cpp


#include <iostream>
	#include "item.h"
	#include "inventory.h"

	#ifdef _WIN32
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
	#include <crtdbg.h>
	#endif

	using namespace std;

	void AddItem(const inventory& inv,char* name,double weight)
	{
	    cout << "Adding " << name << " with a weight of " << weight << "." << endl;
	    inv.AddItem(item(name,weight));
	}

	void RemoveItem(inventory& inv,char* name)
	{
	    cout << "Removing " << name << "." << endl;
	    inv.RemoveItem(name);
	}

	void doTest()
	{
	    inventory inv;

	    // Make sure printing an empty inventory works
	    inv.PrintInventory();

	    // Make sure adding the first one works
	    AddItem(inv,"helmet",5);
	    inv.PrintInventory();

	    // Add some more items
	    AddItem(inv,"braclet of power",1);
	    AddItem(inv,"red potion",2);
	    inv.PrintInventory();

	    // Add some duplicates
	    AddItem(inv,"braclet of power",1);
	    inv.PrintInventory();

	    // Add some heavy stuff
	    AddItem(inv,"bag of gold coins",50);
	    AddItem(inv,"bag of gold coins",50);

	    // Now some removes
	    RemoveItem(inv,"short sword");
	    RemoveItem(inv,"helmet");
	    RemoveItem(inv,"braclet of power");
	    inv.PrintInventory();

	    RemoveItem(inv,"braclet of power");
	    RemoveItem(inv,"red potion");
	    inv.PrintInventory();
	}

	int main() {

  doTest();

	#ifdef _WIN32
	    if (_CrtDumpMemoryLeaks()) {
	        cout << "Memory leaks!" << endl;
	    }
	#endif

	    return 0;
	}





item.h :



    #ifndef ITEM_H
    #define ITEM_H
    #include <cstring>
    #include <string>
	 
	    const int MAXCHAR = 101;
	    const int MAXWEIGHT = 100;
	 
	    class item
	    {
	    private:
	        char    *name;
	        double  weight;
	        int     count;
	 
	    public:
	        //constructors
	        item();
	        item(char [], double);
	 
	        //destructors
	        ~item();





item.cpp


#include "item.h"
#include <iostream>
#include <cstring>
int main(){}
using namespace std;

//private data members
    //char    *name;
	//double  weight;
	//int     count;

//default constructor
	item::item()
{
    name = new char[MAXCHAR];
    strcpy(name, " ");
    weight = 0;
}

//constructor with intial parameters
	item::item(char initName[], double initWeight){

        name = new char[strlen(initName) + 1];
	    strcpy(name, initName);
        weight = initWeight;
}

//Destructor
	item::~item()
{
    if(name)
   {
        delete [] name;
}
    name = NULL;
}


	void item::GetName(char *returnName) const
	{
	    strcpy(returnName, name);
	}

	
	double item::GetWeight() const
	{
	    return weight;
	}

	
	int item::GetCount() const
	{
	    return count;
	}

	
	void item::SetName(char newName[])
	{
	    if(name)
	    {
	        delete [] name;
	        name = NULL;
	    }
	    name = new char[strlen(newName) + 1];
	    strcpy(name, newName);
	}


	void item::SetWeight(double newWeight)
	{
	    weight = newWeight;
	}


	void item::SetCount(int newCount)
	{
	    count = newCount;
	}






inventory.h



        //class: inventory
	    //data members: head, tail

	    #ifndef INVENTORY_H
	    #define INVENTORY_H
        #include "item.h"

	    const int CAP = 2;
	    const int GROWTH = 2;

	    struct Node
	    {
	        item data;
	        Node *next;
	    };

	    class inventory
	    {
	    private:
	        //data members
	        Node *head;
	        Node *tail;

	    public:
	        //constructors
	        inventory();

	        //copy constructor
	        inventory(const inventory &);

	        //destructor
	        ~inventory();

	        //database functions
	        void AddItem(char* name, double weight);;
	        void Add(const item & anItem);
            void RemoveItem(char []);
	        void PrintInventory() const;
	    };

	    //others functions
	    void lowerCase(char []);

	    #endif




inventory.cpp


 


	#include <iostream>
	#include <iomanip>
	#include <cstring>
	#include "inventory.h"

	using namespace std;

	//private data members
	//Node *head;
	//Node *tail;

	//default constructor
	    inventory::inventory()
	{
            head = NULL;
	        tail = NULL;
	}

	    //copy constructor
	    inventory::inventory(const inventory& anInventory)
	    {
	        char tempName[MAXCHAR];

	        //anInventory is empty
	        if(anInventory.head == NULL)
	        {
	            head = NULL;
	        }
	        else
	        {
	            //copy the first node
	            head = new Node;
	            anInventory.head->data.GetName(tempName);
	            head->data.SetName(tempName);
	            head->data.SetWeight(anInventory.head->data.GetWeight());
	            head->data.SetCount(anInventory.head->data.GetCount());

	            //copy the rest of the linked list
	            Node *currSrc = anInventory.head->next;
	            Node *currDest = head;
	            while(currSrc)
	            {
	                currDest->next = new Node;
	                currDest = currDest->next;
	                currSrc->data.GetName(tempName);
	                currDest->data.SetName(tempName);
	                currDest->data.SetWeight(currSrc->data.GetWeight());
	                currDest->data.SetCount(currSrc->data.GetCount());

                currSrc = currSrc->next;
	            }
	            currDest->next = NULL;
	        }
	    }

	    //destructor
	    inventory::~inventory()
	    {
	        Node *curr;
	        if(head)
	        {
	            curr = head;
	        }
	        while(curr)
	        {
	            curr = curr->next;
	            delete head;
	            head = curr;
	        }
	        head = NULL;
	        curr = NULL;
	    }



    void inventory::Add(const item & anItem)
	    {
	        char tempName[MAXCHAR], newNodeName[MAXCHAR];
	        Node *newNode, *curr, *prev;

	        newNode = new Node;
	        anItem.GetName(newNodeName);
	        newNode->data.SetName(newNodeName);
	        lowerCase(newNodeName);
	        newNode->data.SetWeight(anItem.GetWeight());
	        newNode->next = NULL;

	        //check max weight
	        Node *tempcurr;
	        double totalWeight = 0;
	        for(tempcurr = head; tempcurr; tempcurr = tempcurr->next)
	        {
	            totalWeight += tempcurr->data.GetWeight();
	        }
	        if(newNode->data.GetWeight() <= MAXWEIGHT)
	        {
	            if(!head)
	            {
	                head = newNode;
	                tail = newNode;
	                newNode->data.SetCount(1);
	            }
	            else
	            {
	                //reset previous to NULL
	                prev = NULL;
	                curr = head;

                //check to see where to insert
	                curr->data.GetName(tempName);
	                lowerCase(tempName);
	                while(curr && (strcmp(tempName, newNodeName) < 0))
	                {
	                    prev = curr;
	                    curr = curr->next;
	                    curr->data.GetName(tempName);
	                    lowerCase(tempName);
	                }

	                //increase weight and count
	                if(strcmp(tempName, newNodeName) == 0)
	                {
	                    curr->data.SetWeight(curr->data.GetWeight()+newNode->data.GetWeight());
	                    curr->data.SetCount(curr->data.GetCount()+1);
	                }
	                //add a new node
	                else
	                {
	                    newNode->next = curr;
	                    if(prev)
	                    {
	                        prev->next = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    else
	                    {
	                        head = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    if(!curr)
	                    {
	                        tail = newNode;
	                        newNode->data.SetCount(1);
	                        newNode->next = NULL;
	                    }
	                }
	            }
	        }
	        cout << "You picked up a " << newNodeName << "." << endl;
	    }


	    void inventory::RemoveItem(char searchName[])
	    {
	        Node *curr, *prev;
	        char tempName[MAXCHAR];
	        bool found = false;
	        lowerCase(searchName);
	        curr = head;
	        prev = NULL;
	        while(curr)
	        {
	            curr->data.GetName(tempName);
	            lowerCase(tempName);
	            if(strcmp(tempName, searchName) == 0)
	            {
	                if(!head)
	                 cout << "Your inventory is empty. Nothing to remove!" << endl;
	                else
	                {
	                    if(prev)
	                        prev->next = curr->next;
	                    else
	                        head = curr->next;
	                    curr->next = NULL;
	                    delete curr;
	                    found = true;
	                }
	            }
	            prev = curr;
	            curr = curr->next;
	        }
	        if(found)
	        {
	            cout << "You dropped a " << searchName << " ." << endl;
	        }
	        if(!found)
	        {
	            cout << "You don't have a " << searchName << " in your inventory." << endl;
	        }
	    }


	    void inventory::PrintInventory() const
	    {
	        char    tempName[MAXCHAR];
	        int     totalItem = 0;
	        double  totalWeight = 0;

	        cout << endl;
	        cout << "Current inventory:" << endl;

	        if(!head)
	        {
	            cout << "\t(no items)" << endl;
	        }
	        else
	        {
	            Node *curr;
	            for(curr = head; curr; curr = curr->next)
	            {
	                curr->data.GetName(tempName);
	                cout << "\t[" << curr->data.GetCount() << "] " << tempName << endl;
	                totalItem += curr->data.GetCount();
	                totalWeight += curr->data.GetWeight();
	            }

	            cout << "Total items: " << totalItem << endl;
	            cout << "Total weight: " << totalWeight << endl;
	        }
	        cout << endl;
	    }


	    void lowerCase(char word[])
	    {
	        int i = 0;
	        while(word[i] != '\0')
	        {
	            word[i] = tolower(word[i]);
	            i++;
	        }
	    }






Errors:

When compiling main.cpp :

main.cpp||In function ‘void AddItem(const inventory&, char*, double)’:|
main.cpp|16|error: no matching function for call to ‘inventory::AddItem(item) const’|
main.cpp|16|note: candidate is:|
inventory.h|35|note: void inventory::AddItem(char*, double)|
inventory.h|35|note:   candidate expects 2 arguments, 1 provided|
main.cpp||In function ‘void doTest()’:|
main.cpp|33|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|37|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|38|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|42|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|46|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|47|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 4 errors, 11 warnings ===|



When compiling item.cpp :

Compiling: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item.cpp
Linking console executable: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item
Process terminated with status 0 (0 minutes, 8 seconds)
0 errors, 0 warnings
 
Checking for existence: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item
Executing: xterm -T '/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item' -e /usr/bin/cb_console_runner "/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item" (in /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1)
Process terminated with status 0 (0 minutes, 19 seconds)
 



when compiling inventory.cpp :

[code]

/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o||In function `_start':|
(.text+0x18)||undefined reference to `main'|
inventory.o||In function `inventory::inventory(inventory const&)':|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::SetName(char*)'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::SetWeight(double)'|
inventory.cpp|| undefined reference to `item::GetCount() const'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::SetName(char*)'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::SetWeight(double)'|
inventory.cpp|| undefined reference to `item::GetCount() const'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.o||In function `inventory::Add(item const&)':|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::SetName(char*)'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::SetWeight(double)'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
inventory.cpp|| undefined reference to `item::SetWeight(double)'|
inventory.cpp|| undefined reference to `item::GetCount() const'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.cpp|| undefined reference to `item::SetCount(int)'|
inventory.o||In function `inventory::RemoveItem(char*)':|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.o||In function `inventory::PrintInventory() const':|
inventory.cpp|| undefined reference to `item::GetName(char*) const'|
inventory.cpp|| undefined reference to `item::GetCount() const'|
inventory.cpp|| undefined reference to `item::GetCount() const'|
inventory.cpp|| undefined reference to `item::GetWeight() const'|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.o||In function `Node::Node()':|
inventory.cpp:(.text._ZN4NodeC2Ev[_ZN4NodeC5Ev]+0xd)||undefined reference to `item::item()'|
inventory.o||In function `Node::~Node()':|
inventory.cpp:(.text._ZN4NodeD2Ev[_ZN4NodeD5Ev]+0xd)||undefined reference to `item::~item()'|
||=== Build finished: 37 errors, 0 warnings ===|

[/code

I don't even know which errors to attack first.
Was This Post Helpful? 0
  • +
  • -

#32 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: C++ inventory

Posted 24 January 2013 - 08:21 PM

Don't bother to move AddItem from main.cpp.

Lets work on the constants.

In main.cpp make string constant - change :

13    void AddItem(const inventory& inv,char* name,double weight)
  // to
      void AddItem(inventory& inv, const char* name, double weight)




In item.h make constructor string parameter constant.

19        item(const char [], double);




In item.cpp make corresponding constructor string parameter constant.

21	    item::item(const char initName[], double initWeight){




In inventory.h rename Add (or you could change the call in main.cpp)

35	    void AddItem(char* name, double weight);;
36	    void Add(const item & anItem);
   // change to
35	    //void AddItem(char* name, double weight);;
36	    void AddItem(const item & anItem);




In inventory.cpp rename Add

076	void inventory::Add(const item & anItem)
   // change to
076	void inventory::AddItem(const item & anItem)




Try and compile and we will see.
Was This Post Helpful? 0
  • +
  • -

#33 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 24 January 2013 - 11:28 PM

Ok that took care of a lot of the errors but there are still a few.


main.cpp



#include <iostream>
	#include "item.h"
	#include "inventory.h"

	#ifdef _WIN32
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
	#include <crtdbg.h>
	#endif

	using namespace std;

	void AddItem(inventory& inv, const char* name, double weight);
	{
	    cout << "Adding " << name << " with a weight of " << weight << "." << endl;
	    inv.AddItem(item(name,weight));
	}

	void RemoveItem(inventory& inv,char* name)
	{
	    cout << "Removing " << name << "." << endl;
	    inv.RemoveItem(name);
	}

	void doTest()
	{
	    inventory inv;

	    // Make sure printing an empty inventory works
	    inv.PrintInventory();

	    // Make sure adding the first one works
	    AddItem(inv,"helmet",5);
	    inv.PrintInventory();

	    // Add some more items
	    AddItem(inv,"braclet of power",1);
	    AddItem(inv,"red potion",2);
	    inv.PrintInventory();

	    // Add some duplicates
	    AddItem(inv,"braclet of power",1);
	    inv.PrintInventory();

	    // Add some heavy stuff
	    AddItem(inv,"bag of gold coins",50);
	    AddItem(inv,"bag of gold coins",50);

	    // Now some removes
	    RemoveItem(inv,"short sword");
	    RemoveItem(inv,"helmet");
	    RemoveItem(inv,"braclet of power");
	    inv.PrintInventory();

	    RemoveItem(inv,"braclet of power");
	    RemoveItem(inv,"red potion");
	    inv.PrintInventory();
	}

	int main() {

  doTest();

	#ifdef _WIN32
	    if (_CrtDumpMemoryLeaks()) {
	        cout << "Memory leaks!" << endl;
	    }
	#endif

	    return 0;
	}




item.h


    #ifndef ITEM_H
    #define ITEM_H
    #include <cstring>
    #include <string>
	 
	    const int MAXCHAR = 101;
	    const int MAXWEIGHT = 100;
	 
	    class item
	    {
	    private:
	        char    *name;
	        double  weight;
	        int     count;
	 
	    public:
	        //constructors
	        item();
	        item(const char [], double);
	 
	        //destructors
	        ~item();







item.cpp



#include "item.h"
#include <iostream>
#include <cstring>
int main(){}
using namespace std;

//private data members
    //char    *name;
	//double  weight;
	//int     count;

//default constructor
	item::item()
{
    name = new char[MAXCHAR];
    strcpy(name, " ");
    weight = 0;
}

//constructor with intial parameters
	item::item(char initName[], double initWeight){

        name = new char[strlen(initName) + 1];
	    strcpy(name, initName);
        weight = initWeight;
}

//Destructor
	item::~item()
{
    if(name)
   {
        delete [] name;
}
    name = NULL;
}


	void item::GetName(char *returnName) const
	{
	    strcpy(returnName, name);
	}


	double item::GetWeight() const
	{
	    return weight;
	}


	int item::GetCount() const
	{
	    return count;
	}


	void item::SetName(char newName[])
	{
	    if(name)
	    {
	        delete [] name;
	        name = NULL;
	    }
	    name = new char[strlen(newName) + 1];
	    strcpy(name, newName);
	}


	void item::SetWeight(double newWeight)
	{
	    weight = newWeight;
	}


	void item::SetCount(int newCount)
	{
	    count = newCount;
	}






inventory.h



        //class: inventory
	    //data members: head, tail

	    #ifndef INVENTORY_H
	    #define INVENTORY_H
        #include "item.h"

	    const int CAP = 2;
	    const int GROWTH = 2;

	    struct Node
	    {
	        item data;
	        Node *next;
	    };

	    class inventory
	    {
	    private:
	        //data members
	        Node *head;
	        Node *tail;

	    public:
	        //constructors
	        inventory();

	        //copy constructor
	        inventory(const inventory &);

	        //destructor
	        ~inventory();

	        //database functions
	        
            void RemoveItem(char []);
            void AddItem(char* name, double weight);
            void AddItem(const item & anItem);
	        void PrintInventory() const;
	    };

	    //others functions
	    void lowerCase(char []);

	    #endif




inventory.cpp



	#include <iostream>
	#include <iomanip>
	#include <cstring>
	#include "inventory.h"

	using namespace std;

	//private data members
	//Node *head;
	//Node *tail;

	//default constructor
	    inventory::inventory()
	{
            head = NULL;
	        tail = NULL;
	}

	    //copy constructor
	    inventory::inventory(const inventory& anInventory)
	    {
	        char tempName[MAXCHAR];

	        //anInventory is empty
	        if(anInventory.head == NULL)
	        {
	            head = NULL;
	        }
	        else
	        {
	            //copy the first node
	            head = new Node;
	            anInventory.head->data.GetName(tempName);
	            head->data.SetName(tempName);
	            head->data.SetWeight(anInventory.head->data.GetWeight());
	            head->data.SetCount(anInventory.head->data.GetCount());

	            //copy the rest of the linked list
	            Node *currSrc = anInventory.head->next;
	            Node *currDest = head;
	            while(currSrc)
	            {
	                currDest->next = new Node;
	                currDest = currDest->next;
	                currSrc->data.GetName(tempName);
	                currDest->data.SetName(tempName);
	                currDest->data.SetWeight(currSrc->data.GetWeight());
	                currDest->data.SetCount(currSrc->data.GetCount());

                currSrc = currSrc->next;
	            }
	            currDest->next = NULL;
	        }
	    }

	    //destructor
	    inventory::~inventory()
	    {
	        Node *curr;
	        if(head)
	        {
	            curr = head;
	        }
	        while(curr)
	        {
	            curr = curr->next;
	            delete head;
	            head = curr;
	        }
	        head = NULL;
	        curr = NULL;
	    }



    void inventory::AddItem(const item & anItem)
	    {
	        char tempName[MAXCHAR], newNodeName[MAXCHAR];
	        Node *newNode, *curr, *prev;

	        newNode = new Node;
	        anItem.GetName(newNodeName);
	        newNode->data.SetName(newNodeName);
	        lowerCase(newNodeName);
	        newNode->data.SetWeight(anItem.GetWeight());
	        newNode->next = NULL;

	        //check max weight
	        Node *tempcurr;
	        double totalWeight = 0;
	        for(tempcurr = head; tempcurr; tempcurr = tempcurr->next)
	        {
	            totalWeight += tempcurr->data.GetWeight();
	        }
	        if(newNode->data.GetWeight() <= MAXWEIGHT)
	        {
	            if(!head)
	            {
	                head = newNode;
	                tail = newNode;
	                newNode->data.SetCount(1);
	            }
	            else
	            {
	                //reset previous to NULL
	                prev = NULL;
	                curr = head;

                //check to see where to insert
	                curr->data.GetName(tempName);
	                lowerCase(tempName);
	                while(curr && (strcmp(tempName, newNodeName) < 0))
	                {
	                    prev = curr;
	                    curr = curr->next;
	                    curr->data.GetName(tempName);
	                    lowerCase(tempName);
	                }

	                //increase weight and count
	                if(strcmp(tempName, newNodeName) == 0)
	                {
	                    curr->data.SetWeight(curr->data.GetWeight()+newNode->data.GetWeight());
	                    curr->data.SetCount(curr->data.GetCount()+1);
	                }
	                //add a new node
	                else
	                {
	                    newNode->next = curr;
	                    if(prev)
	                    {
	                        prev->next = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    else
	                    {
	                        head = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    if(!curr)
	                    {
	                        tail = newNode;
	                        newNode->data.SetCount(1);
	                        newNode->next = NULL;
	                    }
	                }
	            }
	        }
	        cout << "You picked up a " << newNodeName << "." << endl;
	    }


	    void inventory::RemoveItem(char searchName[])
	    {
	        Node *curr, *prev;
	        char tempName[MAXCHAR];
	        bool found = false;
	        lowerCase(searchName);
	        curr = head;
	        prev = NULL;
	        while(curr)
	        {
	            curr->data.GetName(tempName);
	            lowerCase(tempName);
	            if(strcmp(tempName, searchName) == 0)
	            {
	                if(!head)
	                 cout << "Your inventory is empty. Nothing to remove!" << endl;
	                else
	                {
	                    if(prev)
	                        prev->next = curr->next;
	                    else
	                        head = curr->next;
	                    curr->next = NULL;
	                    delete curr;
	                    found = true;
	                }
	            }
	            prev = curr;
	            curr = curr->next;
	        }
	        if(found)
	        {
	            cout << "You dropped a " << searchName << " ." << endl;
	        }
	        if(!found)
	        {
	            cout << "You don't have a " << searchName << " in your inventory." << endl;
	        }
	    }


	    void inventory::PrintInventory() const
	    {
	        char    tempName[MAXCHAR];
	        int     totalItem = 0;
	        double  totalWeight = 0;

	        cout << endl;
	        cout << "Current inventory:" << endl;

	        if(!head)
	        {
	            cout << "\t(no items)" << endl;
	        }
	        else
	        {
	            Node *curr;
	            for(curr = head; curr; curr = curr->next)
	            {
	                curr->data.GetName(tempName);
	                cout << "\t[" << curr->data.GetCount() << "] " << tempName << endl;
	                totalItem += curr->data.GetCount();
	                totalWeight += curr->data.GetWeight();
	            }

	            cout << "Total items: " << totalItem << endl;
	            cout << "Total weight: " << totalWeight << endl;
	        }
	        cout << endl;
	    }


	    void lowerCase(char word[])
	    {
	        int i = 0;
	        while(word[i] != '\0')
	        {
	            word[i] = tolower(word[i]);
	            i++;
	        }
	    }




ERRORS


When compiling main.cpp :

main.cpp|14|error: expected unqualified-id before ‘{’ token|
main.cpp||In function ‘void doTest()’:|
main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 1 errors, 5 warnings ===|




When compiling item.cpp :

Compiling: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item.cpp
Linking console executable: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item
Process terminated with status 0 (0 minutes, 6 seconds)
0 errors, 0 warnings
 
Checking for existence: /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item
Executing: xterm -T '/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item' -e /usr/bin/cb_console_runner "/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/item" (in /media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1)




When compiling inventory.cpp :

/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.cpp|77|error: prototype for ‘void inventory::AddItem(const item&)’ does not match any in class ‘inventory’|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.h|35|error: candidate is: void inventory::AddItem(char*, double)|
||=== Build finished: 2 errors, 0 warnings ===|





I am so close...I can taste it...
Was This Post Helpful? 0
  • +
  • -

#34 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: C++ inventory

Posted 24 January 2013 - 11:40 PM

Well, you have a semicolon in your line 13 of main.cpp.

You should only use semicolon in function calls and function prototyping and not in function definition.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#35 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 24 January 2013 - 11:43 PM

Aparently the prototypes arent matching still
Was This Post Helpful? 0
  • +
  • -

#36 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 24 January 2013 - 11:57 PM

Ok, I removed the semicolon in the function definition but I get these errors still

for main.cpp :

main.cpp||In function ‘void AddItem(inventory&, const char*, double)’:|
main.cpp|16|error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]|
item.h|27|error:   initializing argument 1 of ‘item::item(char*, double)’ [-fpermissive]|
main.cpp|16|error: no matching function for call to ‘inventory::AddItem(item)’|
main.cpp|16|note: candidate is:|
inventory.h|35|note: void inventory::AddItem(char*, double)|
inventory.h|35|note:   candidate expects 2 arguments, 1 provided|
main.cpp||In function ‘void doTest()’:|
main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 6 errors, 5 warnings ===|




for inventory.cpp:

/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.cpp|77|error: prototype for ‘void inventory::AddItem(const item&)’ does not match any in class ‘inventory’|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.h|35|error: candidate is: void inventory::AddItem(char*, double)|
||=== Build finished: 2 errors, 0 warnings ===|


Was This Post Helpful? 0
  • +
  • -

#37 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: C++ inventory

Posted 25 January 2013 - 01:55 AM

For your error in line 16 of your Main.cpp...it is because your function call is wrong.

  inv.AddItem(item(name,weight));


If you look at the code closely, you seem to be calling a function that has

AddItem(item)


and in your code, there is no function which exists that takes that kind of argument.

I think you probably meant

  inv.AddItem(item,name,weight));


regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#38 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 25 January 2013 - 02:31 AM

ok I changed the function call on line 16, but I still have 1 error when trying to compile main.cpp:

main.cpp||In function ‘void AddItem(inventory&, const char*, double)’:|
main.cpp|16|error: expected primary-expression before ‘,’ token|
main.cpp||In function ‘void doTest()’:|
main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
/main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 1 errors, 5 warnings ===|



And the 2 errors when compiling inventory.cpp :

inventory.cpp|77|error: prototype for ‘void inventory::AddItem(const item&)’ does not match any in class ‘inventory’|
inventory.h|35|error: candidate is: void inventory::AddItem(char*, double)|
||=== Build finished: 2 errors, 0 warnings ===|


Was This Post Helpful? 0
  • +
  • -

#39 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: C++ inventory

Posted 25 January 2013 - 02:33 AM

Can you please post your updated line 16 of main.cpp here?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#40 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 25 January 2013 - 02:48 AM

main.cpp

#include <iostream>
	#include "item.h"
	#include "inventory.h"

	#ifdef _WIN32
	#define _CRTDBG_MAP_ALLOC
	#include <stdlib.h>
	#include <crtdbg.h>
	#endif

	using namespace std;

	void AddItem(inventory& inv, const char* name, double weight)
	{
	    cout << "Adding " << name << " with a weight of " << weight << "." << endl;
	    inv.AddItem(item,name,weight);
	}

	void RemoveItem(inventory& inv,char* name)
	{
	    cout << "Removing " << name << "." << endl;
	    inv.RemoveItem(name);
	}

	void doTest()
	{
	    inventory inv;

	    // Make sure printing an empty inventory works
	    inv.PrintInventory();

	    // Make sure adding the first one works
	    AddItem(inv,"helmet",5);
	    inv.PrintInventory();

	    // Add some more items
	    AddItem(inv,"braclet of power",1);
	    AddItem(inv,"red potion",2);
	    inv.PrintInventory();

	    // Add some duplicates
	    AddItem(inv,"braclet of power",1);
	    inv.PrintInventory();

	    // Add some heavy stuff
	    AddItem(inv,"bag of gold coins",50);
	    AddItem(inv,"bag of gold coins",50);

	    // Now some removes
	    RemoveItem(inv,"short sword");
	    RemoveItem(inv,"helmet");
	    RemoveItem(inv,"braclet of power");
	    inv.PrintInventory();

	    RemoveItem(inv,"braclet of power");
	    RemoveItem(inv,"red potion");
	    inv.PrintInventory();
	}

	int main() {

  doTest();

	#ifdef _WIN32
	    if (_CrtDumpMemoryLeaks()) {
	        cout << "Memory leaks!" << endl;
	    }
	#endif

	    return 0;
	}




item.h :


    #ifndef ITEM_H
    #define ITEM_H
    #include <cstring>
    #include <string>
	 
	    const int MAXCHAR = 101;
	    const int MAXWEIGHT = 100;
	 
	    class item
	    {
	    private:
	        char    *name;
	        double  weight;
	        int     count;
	 
	    public:
	        //constructors
	        item();
	        item(const char [], double);
	 
	        //destructors
	        ~item();




item.cpp :


#include "item.h"
#include <iostream>
#include <cstring>
int main(){}
using namespace std;

//private data members
    //char    *name;
	//double  weight;
	//int     count;

//default constructor
	item::item()
{
    name = new char[MAXCHAR];
    strcpy(name, " ");
    weight = 0;
}

//constructor with intial parameters
	item::item(char initName[], double initWeight){

        name = new char[strlen(initName) + 1];
	    strcpy(name, initName);
        weight = initWeight;
}

//Destructor
	item::~item()
{
    if(name)
   {
        delete [] name;
}
    name = NULL;
}


	void item::GetName(char *returnName) const
	{
	    strcpy(returnName, name);
	}


	double item::GetWeight() const
	{
	    return weight;
	}


	int item::GetCount() const
	{
	    return count;
	}


	void item::SetName(char newName[])
	{
	    if(name)
	    {
	        delete [] name;
	        name = NULL;
	    }
	    name = new char[strlen(newName) + 1];
	    strcpy(name, newName);
	}


	void item::SetWeight(double newWeight)
	{
	    weight = newWeight;
	}


	void item::SetCount(int newCount)
	{
	    count = newCount;
	}




inventory.h:

        //class: inventory
	    //data members: head, tail

	    #ifndef INVENTORY_H
	    #define INVENTORY_H
        #include "item.h"

	    const int CAP = 2;
	    const int GROWTH = 2;

	    struct Node
	    {
	        item data;
	        Node *next;
	    };

	    class inventory
	    {
	    private:
	        //data members
	        Node *head;
	        Node *tail;

	    public:
	        //constructors
	        inventory();

	        //copy constructor
	        inventory(const inventory &);

	        //destructor
	        ~inventory();

	        //database functions
	        
            void RemoveItem(char []);
            void AddItem(char* name, double weight);
            void AddItem(const item & anItem);
	        void PrintInventory() const;
	    };

	    //others functions
	    void lowerCase(char []);

	    #endif




inventory.cpp:


	#include <iostream>
	#include <iomanip>
	#include <cstring>
	#include "inventory.h"

	using namespace std;

	//private data members
	//Node *head;
	//Node *tail;

	//default constructor
	    inventory::inventory()
	{
            head = NULL;
	        tail = NULL;
	}

	    //copy constructor
	    inventory::inventory(const inventory& anInventory)
	    {
	        char tempName[MAXCHAR];

	        //anInventory is empty
	        if(anInventory.head == NULL)
	        {
	            head = NULL;
	        }
	        else
	        {
	            //copy the first node
	            head = new Node;
	            anInventory.head->data.GetName(tempName);
	            head->data.SetName(tempName);
	            head->data.SetWeight(anInventory.head->data.GetWeight());
	            head->data.SetCount(anInventory.head->data.GetCount());

	            //copy the rest of the linked list
	            Node *currSrc = anInventory.head->next;
	            Node *currDest = head;
	            while(currSrc)
	            {
	                currDest->next = new Node;
	                currDest = currDest->next;
	                currSrc->data.GetName(tempName);
	                currDest->data.SetName(tempName);
	                currDest->data.SetWeight(currSrc->data.GetWeight());
	                currDest->data.SetCount(currSrc->data.GetCount());

                currSrc = currSrc->next;
	            }
	            currDest->next = NULL;
	        }
	    }

	    //destructor
	    inventory::~inventory()
	    {
	        Node *curr;
	        if(head)
	        {
	            curr = head;
	        }
	        while(curr)
	        {
	            curr = curr->next;
	            delete head;
	            head = curr;
	        }
	        head = NULL;
	        curr = NULL;
	    }



    void inventory::AddItem(const item & anItem)
	    {
	        char tempName[MAXCHAR], newNodeName[MAXCHAR];
	        Node *newNode, *curr, *prev;

	        newNode = new Node;
	        anItem.GetName(newNodeName);
	        newNode->data.SetName(newNodeName);
	        lowerCase(newNodeName);
	        newNode->data.SetWeight(anItem.GetWeight());
	        newNode->next = NULL;

	        //check max weight
	        Node *tempcurr;
	        double totalWeight = 0;
	        for(tempcurr = head; tempcurr; tempcurr = tempcurr->next)
	        {
	            totalWeight += tempcurr->data.GetWeight();
	        }
	        if(newNode->data.GetWeight() <= MAXWEIGHT)
	        {
	            if(!head)
	            {
	                head = newNode;
	                tail = newNode;
	                newNode->data.SetCount(1);
	            }
	            else
	            {
	                //reset previous to NULL
	                prev = NULL;
	                curr = head;

                //check to see where to insert
	                curr->data.GetName(tempName);
	                lowerCase(tempName);
	                while(curr && (strcmp(tempName, newNodeName) < 0))
	                {
	                    prev = curr;
	                    curr = curr->next;
	                    curr->data.GetName(tempName);
	                    lowerCase(tempName);
	                }

	                //increase weight and count
	                if(strcmp(tempName, newNodeName) == 0)
	                {
	                    curr->data.SetWeight(curr->data.GetWeight()+newNode->data.GetWeight());
	                    curr->data.SetCount(curr->data.GetCount()+1);
	                }
	                //add a new node
	                else
	                {
	                    newNode->next = curr;
	                    if(prev)
	                    {
	                        prev->next = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    else
	                    {
	                        head = newNode;
	                        newNode->data.SetCount(1);
	                    }
	                    if(!curr)
	                    {
	                        tail = newNode;
	                        newNode->data.SetCount(1);
	                        newNode->next = NULL;
	                    }
	                }
	            }
	        }
	        cout << "You picked up a " << newNodeName << "." << endl;
	    }


	    void inventory::RemoveItem(char searchName[])
	    {
	        Node *curr, *prev;
	        char tempName[MAXCHAR];
	        bool found = false;
	        lowerCase(searchName);
	        curr = head;
	        prev = NULL;
	        while(curr)
	        {
	            curr->data.GetName(tempName);
	            lowerCase(tempName);
	            if(strcmp(tempName, searchName) == 0)
	            {
	                if(!head)
	                 cout << "Your inventory is empty. Nothing to remove!" << endl;
	                else
	                {
	                    if(prev)
	                        prev->next = curr->next;
	                    else
	                        head = curr->next;
	                    curr->next = NULL;
	                    delete curr;
	                    found = true;
	                }
	            }
	            prev = curr;
	            curr = curr->next;
	        }
	        if(found)
	        {
	            cout << "You dropped a " << searchName << " ." << endl;
	        }
	        if(!found)
	        {
	            cout << "You don't have a " << searchName << " in your inventory." << endl;
	        }
	    }


	    void inventory::PrintInventory() const
	    {
	        char    tempName[MAXCHAR];
	        int     totalItem = 0;
	        double  totalWeight = 0;

	        cout << endl;
	        cout << "Current inventory:" << endl;

	        if(!head)
	        {
	            cout << "\t(no items)" << endl;
	        }
	        else
	        {
	            Node *curr;
	            for(curr = head; curr; curr = curr->next)
	            {
	                curr->data.GetName(tempName);
	                cout << "\t[" << curr->data.GetCount() << "] " << tempName << endl;
	                totalItem += curr->data.GetCount();
	                totalWeight += curr->data.GetWeight();
	            }

	            cout << "Total items: " << totalItem << endl;
	            cout << "Total weight: " << totalWeight << endl;
	        }
	        cout << endl;
	    }


	    void lowerCase(char word[])
	    {
	        int i = 0;
	        while(word[i] != '\0')
	        {
	            word[i] = tolower(word[i]);
	            i++;
	        }
	    }




EROOR OUTPUT

from main.cpp
main.cpp||In function ‘void AddItem(inventory&, const char*, double)’:|
main.cpp|16|error: expected primary-expression before ‘,’ token|
main.cpp||In function ‘void doTest()’:|
main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 1 errors, 5 warnings ===|
[/code

from inventory.cpp

[code]
inventory.cpp|77|error: prototype for ‘void inventory::AddItem(const item&)’ does not match any in class ‘inventory’|
inventory.h|35|error: candidate is: void inventory::AddItem(char*, double)|
||=== Build finished: 2 errors, 0 warnings ===|


Was This Post Helpful? 0
  • +
  • -

#41 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: C++ inventory

Posted 25 January 2013 - 03:00 AM

Well, if you notice in your inventory.h, there is no function taking 3 parameters...so I guess you need to change that line 37 of inventory.h to
void AddItem(inventory &inv, char* name, double weight);


regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#42 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 25 January 2013 - 03:12 AM

from inventory.h:

void RemoveItem(char []);
            void AddItem(inventory &inv, char* name, double weight);
            void AddItem(const item & anItem);
	        void PrintInventory() const;



I changed it, but I am still getting the same error for inventory.cpp

/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.cpp|77|error: prototype for ‘void inventory::AddItem(const item&)’ does not match any in class ‘inventory’|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/inventory.h|35|error: candidate is: void inventory::AddItem(char*, double)|
||=== Build finished: 2 errors, 0 warnings ===|



Was This Post Helpful? 0
  • +
  • -

#43 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: C++ inventory

Posted 25 January 2013 - 03:14 AM

What about the errors in main.cpp...are they gone?

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#44 sydewayzlocc  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 79
  • Joined: 18-April 12

Re: C++ inventory

Posted 25 January 2013 - 12:54 PM

Im sorry I have the following errors when compiling main.cpp :


/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp||In function ‘void AddItem(inventory&, const char*, double)’:|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|16|error: expected primary-expression before ‘,’ token|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp||In function ‘void doTest()’:|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|51|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|52|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|55|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|56|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|
||=== Build finished: 1 errors, 5 warnings ===|


Was This Post Helpful? 0
  • +
  • -

#45 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1398
  • View blog
  • Posts: 4,873
  • Joined: 19-February 09

Re: C++ inventory

Posted 25 January 2013 - 02:50 PM

Let us look at one of the errors/warnings :

/media/8c51a03d-e51b-4391-bab9-90222b696438/School/CS260/lab1/main.cpp|50|warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]|




This says it is in main.cpp, line 50, and has to do with constant to char*:

main.cpp
50        RemoveItem(inv,"short sword");




This is similar to the change we made with AddItem, where we added const to the parameter.

The string "short sword" is a constant string, for a function to accept this the parameter should be const as well as any sub-function parameters that use the string. This is basically saying you are not going to alter the string.
Was This Post Helpful? 0
  • +
  • -

  • (7 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »