Hi all,
I have experiencing a couple of problems with a project that I am doing for school. Unfortunately in trying to write a cut down version of the code so I can explaing my problem, I have come across another issue that I cannot solve.
Any ideas?
Given the following code, I get this error:
main.cpp(11): error C2243: 'type cast' : conversion from 'CFlower *' to 'CPlant *' exists, but is inaccessibleCode:#ifndef CPLANT_H_ #define CPLANT_H_ #include <iostream> #include <cstring> using namespace std; class CPlant { private: char *plantName; public: CPlant(char *); ~CPlant(void); char* getPlantName(void); }; #endif // CPLANT_H_Code:#include "CPlant.h" CPlant::CPlant(char* name) { plantName = NULL; plantName = new char[strlen(name) + 1]; strcpy(plantName, name); } CPlant::~CPlant(void) { if (plantName) { delete [] plantName; plantName = NULL; } } char * CPlant::getPlantName(void) { return plantName; }Code:#ifndef CFLOWER_H_ #define CFLOWER_H_ #include <iostream> #include <cstring> #include "CPlant.h" using namespace std; class CFlower : CPlant { private: char *flowerColor; public: CFlower(char *, char *); ~CFlower(void); char* getFlowerColor(void); }; #endif // CFLOWER_H_Code:#include "CFlower.h" CFlower::CFlower(char *name, char *color) : CPlant(name) { flowerColor = NULL; flowerColor = new char [strlen(color) + 1]; strcpy(flowerColor, color); } CFlower::~CFlower(void) { if (flowerColor) { delete [] flowerColor; flowerColor = NULL; } } char* CFlower::getFlowerColor(void) { return flowerColor; }Code:#include <iostream> #include "CPlant.h" #include "CFlower.h" using namespace std; int main(void) { CPlant *plant[2]; plant[0] = new CFlower("Rose", "Red"); plant[1] = new CFlower("Rose", "Yellow"); return 0; }



LinkBack URL
About LinkBacks


