Hi,

I'm implementing a nested class and trying to implement some related functions in it. But it seems that no way whatsoever it decides to work. Could you please help me as I'm getting really exhausted.

Thanks a lot.

#ifndef STOCKLIST_H
#define STOCKLIST_H


#include <string>
using namespace std;



typedef string dvdTitle;


class stockList
{
        public:
		stockList();	/* Constructor */
		stockList(const stockList& StList);	/* Copy Constructor */
		~stockList();	/* Destructor */

		bool isEmpty() const;	/* Return wether list is empty or not */

		int getLength() const;	/* Return the size of the list */

		void insertTitle(string ID, const dvdTitle newTitle, int year, int want, int have);  /*Insert the item in index) */
		
		void insertWho(string ID, string who);

		void removeTitle(string ID);	/* Remove the item designated by index */

		void removeWho(string ID);	/* Remove the name from the wait list */

		void retrieve(string ID);	/* Retrieve the item designated by index */



        private:
	    struct waitNode // Structure for the costumer information
	    {
		string ID;
		string who;
		waitNode *next;
	    };


	class stockItem 
	{
	    public:
		    void setID(string ID);
		    string getID();
		    void setTitle(string title);
		    string getTitle();
		    void setYear(int year);
		    int getYear();
		    void setWant(int want);
		    int getWant();
		    void setHave(int have);
		    int getHave();

	    	    
	    private:
		    string ID;
		    string title;
		    int have, want, year;

	};


	struct stockNode  // Main 
	{
	    stockItem item;
	    waitNode *waitHead, *waitTail;
	    stockNode *next;    
	};

	stockNode *head;


};

and after the class declaration, here is what I have done for my "void insertTitle".

void stockList::insertTitle(string ID, const dvdTitle newTitle, int year, int want, int have)
{
	stockNode *cur = head;

	for (cur = head; cur != NULL; cur = cur -> next)
	{
		if ((cur -> item).getID() == ID)
		{
			cerr << "Item already existed";
			exit(1);
		}

		continue;
	}


	cur -> next = new stockNode;

	(cur->item).setID(ID);
	(cur->item).setTitle(newTitle);
	(cur->item).setYear(year);
	(cur->item).setWant(want);
	(cur->item).setHave(have);
	cur->next = NULL;

}

and when I compile, it says that no reference is defined to stockList::stockNode::getID() or setID() and so forth.

thanks again.

Recommended Answers

All 7 Replies

I didn't find any ambiguity in your code. Please justify your code.

I didn't find any ambiguity in your code. Please justify your code.

Yeah, exactly, that's the problem. It seems that the code should be correct, but it turns out that it doesn't work. As I mentioned before, it just states that no referencing to that function call. I really don't know why....

Can you post complete code? You may use attachment feature also.

sure thing.

Method are implemented (defined) in class stockItem.

....
	class stockItem
	{
	    public:
		    void setID(string ID) { this->ID=ID;}
		    string getID() {return ID; };
		    void setTitle(string title) { this->title=title;}
		    string getTitle() { return title;}
		    void setYear(int year) {this->year=year; }
		    int getYear() { return year;}
		    void setWant(int want) { this->want=want;}
		    int getWant() { return want;}
		    void setHave(int have) { this->have=have;}
		    int getHave() { return have;}
	    private:
		    string ID;
		    string title;
		    int have, want, year;
	};
    .....
commented: Thanks, it was nice +1

I can't believe I did that. Anyhow, thanks a lot man.

Yeh, you did that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.