I have a find function to a find a name and then return a class. I will show you parts i think you will need to help me.
In main()
Code:
list *wineries = new list();
winery *wPtr;
wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95));
wineries->insert(winery("Gallo", "Napa Valley", 200, 25));
wineries->insert(winery("Cooper Mountain", "Willamette Valley", 100, 47));
cout << "\n+++ list by rating\n";
wineries->displayByRating(cout);
cout << "\n>>> search for \"Gallo\"\n\n";
wPtr = wineries->find("Gallo"); // Where my problem lies
if (wPtr != 0)
cout << wPtr;
else
cout << "not found" << endl;
cout << "\n>>> search for \"No Such\"\n\n";
wPtr = wineries->find("No Such");
if (wPtr != 0)
cout << wPtr;
Code:
winery * const list::find(const char * const name) const
{
node * curr;
winery *wPtr;
//wPtr = NULL;
for(curr=headByName; curr; curr=curr->nextByName)
{
if(strcmp(curr->item.getName(), name) == 0)
{
wPtr = curr->item; // causing error
return wPtr;
}
}
Code:
#ifndef _WINERY_
#define _WINERY_
#include <ostream>
class winery
{
public:
winery(const char * const name, const char * const location, const int acres, const int rating);
virtual ~winery(void);
const char * const getName() const;
const char * const getLocation() const;
const int getAcres() const;
const int getRating() const;
// display headings for lists of wineries
static void displayHeadings(std::ostream& out);
friend std::ostream& operator<<(std::ostream& out, winery *w);
private:
char *name;
char *location;
int acres;
int rating;
};
#endif // _WINERY_
Code:
#ifndef _LIST_
#define _LIST_
#include <ostream>
#include "winery.h"
using namespace std;
class list
{
public:
list(void); // constructor
virtual ~list(void); // destructor
void displayByName(ostream& out) const;
void displayByRating(ostream& out) const;
void insert(const winery& winery);
winery * const find(const char * const name) const;
bool remove(const char * const name);
private:
struct node
{
node(const winery& winery); // constructor
winery item;
node * nextByName;
node * nextByRating;
};
node * headByName;
node * headByRating;
};
#endif // _LIST_
Error i get: error C2440: '=' : cannot convert from 'winery' to 'winery *'
I dont know how else to do this?
I dont know why the code dont line up better i have it VS set to tab 4
Thank you