I'm trying to initialize an instance of a class called "Winery" using an initialization list in the constructor for another class called "List." The problem is that when I hand the Winery constructor a winery to copy, it fails to copy the information.
This the header file for the Winery class:
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 { return name; }
const char * const getLocation() const { return location; }
const int getAcres() const { return acres; }
const int getRating() const { return rating; }
private:
char *name;
char *location;
int acres;
int rating;
};
Here is the relevant part of the header file for my List class:
struct Node
{
Node(const Winery& winery);
Winery item;
Node *nextByName;
Node *nextByRating;
};
Here is the constructor in my List class:
List::Node::Node(const Winery& winery) :
item(winery.getName(),
winery.getLocation(),
winery.getAcres(),
winery.getRating()),
nextByName(nullptr),
nextByRating(nullptr)
{
}
From what I see, it looks like I'm doing everything I need to be doing. The data members of the winery that I'm passing to the constructor are private, so I'm trying to get them via the functions that get information. They're in the proper order and everything.
The pointers work just fine after I initialize them, but the information isn't there, so I really don't know what to do here. If you're wondering, this is for an assignment and we have to use initialization lists (I've tried it without them and that doesn't work either so I really don't know what to do).
Here is my Winery constructor:
Winery::Winery(const char * const name,
const char * const location,
const int acres,
const int rating) :
acres(acres),
rating(rating)
{
char *newName = new char[sizeof(name) + 1];
char *newLocation = new char[sizeof(location) + 1];
}
newNameandnewLocationstrings. Is there a reason you're not usingconst char*instead ofstd::string?item,nextByName, andnextByRatingin memory.nextByNameandnextByRatinghave been initialized toNULL, but all four parts ofitemstill have the Visual Studio default memory values in them (0xcdcdcdcd, 0xfeeffeef, etc.) And the reason I'm usingconst char*is because we have been disallowed from usingstd::string.