I have a media program. i am adding CD,dvd,book info. I managed to get the book info added to the set. I am now adding the CD info. I have most of the Cd info added but i have a seperate function for adding band members. thats where i need help!
I am getting a cast error: error C2440: ‘type cast’ : cannot convert from ‘const Item *const ‘ to ‘CD’
CD.h
#ifndef CD_H
#define CD_H
#pragma once
#include "item.h"
class CD : public Item
{
public:
CD(const string& theTitle, const string& theBand, const int snumber);
const string addBandMember(const string& member);
const int getNumber() const;
const string getMusician() const;
const string getBand() const;
virtual void print(ostream& out) const;
~CD();
private:
string band;
string musicians;
string title;
int number;
};
ostream& operator<<(ostream& out, const CD* cd);
#endif
CD.cpp
const string CD::addBandMember(const string &member)
{
return this->musicians = member;
}
In
Library::addBandMemberyou’re trying to cast a pointer to a class typeyou need to cast to
CD*notCDAnd you probably don’t want the 2 const in
since you want to modify the
musicCD!finally your
CD::addBandMembermethod doesn’t seem to add a band member but replace it.