I'm writing a class shape which uses the member function
setName( char *objectname) to allocate free space for a new object name using "new"....i'm getting this error however and can't seem to fix it
here's the corresponding code...
setName( char *objectname) to allocate free space for a new object name using "new"....i'm getting this error however and can't seem to fix it
code:<HR>Code::\shapei.cpp(25) : error C2440: '=' : cannot convert from 'char *' to 'char [99]' There are no conversions to array types, although there are conversions to references or pointers to arrays
here's the corresponding code...
and...code:<HR>Code:#ifndef shapei_h #define shapei_h<P>#include <iostream.h><P>class Shape { friend ostream & operator<<(ostream &output, const Shape &s);<P>public: Shape( char *object); ~Shape(); void printShape() const; void print() const; void printArea() const; void printPerimeter() const; void setName( char *name); const char *getName() const {return name;}<P>protected:<P>static int objectcount; double area, perimeter;<P>private: char name[99]; <P>};<P>#endif
code:<HR>Code:#include <iostream.h> #include "shapei.h" #include <string.h> #include <assert.h> int Shape::objectcount = 0;<P>Shape::Shape( char *object) { area = 0; perimeter = 0; strcpy( name, object ); objectcount++; cout << "The Number of objects is: " << objectcount << endl; }<P>Shape::~Shape() { objectcount--; cout << "The number of objects is: " << objectcount << endl;<P>}<P>void Shape::setName(char *objectname) { name = new char [ strlen(objectname) + 1]; assert( name != 0); strcpy( name, objectname); } void Shape::printShape() const { cout << "The Shape is ?" << endl; <P> }<P>void Shape::print() const { cout << "The object: " << getName() << " with"; } void Shape::printArea() const { cout << "\tarea = " << area << endl; }<P>void Shape::printPerimeter() const { cout << "\tperimeter = " << perimeter << endl;<P>}<P>ostream &operator<<(ostream &output, const Shape &s) { s.printShape(); s.printArea(); s.printPerimeter(); return output; }