Code:
/* 3. Modify 2. Such that the constructor is overloaded to take 2 parameters
of type char pointer. Use these parameters to initialise the private members.
This constructor should also be in-line as in question 2.
Create 2 objects by using both constructors. Output the two default sets of details
then modify them with the member functions and output the new values */
#include <iostream.h>
#include <stdio.h>
class TShape
{
private:
char* itsColour;
char* itsShape;
public:
void SetColour(char* pColour);
void SetShape(char* pShape);
void SetColour(void);
void SetShape(void);
char* GetColour(void);
char* GetShape(void);
TShape(void) {itsShape ="Square"; itsColour="Red";};
TShape(char* pColour, char* pShape);
}; //end TShape Class
//Private data access function to set data
void TShape::SetColour(char* pColour)
{
itsColour = pColour;
}
//private data access function to set data
void TShape::SetShape(char* pShape)
{
itsShape = pShape;
}
//private data access function to get data
char* TShape::GetColour(void)
{
return itsColour;
}
//private data access function to get data
char* TShape::GetShape(void)
{
return itsShape;
}
inline TShape::TShape(char* pColour, char* pShape)
{
itsShape = pShape;
itsColour = pColour;
}
void main()
{
TShape obj1("Green","Octagon"),
obj2(),
obj3;
cout<<"Object 1 is a "<< obj1.GetColour()<<" "<< obj1.GetShape() <<" \n";
cout<<"Object 2 is a "<< obj2.GetColour()<<" "<< obj2.GetShape() <<" \n";
obj1.SetColour("Purple");
obj1.SetShape("Egg");
cout<<"Object 3 is a "<< obj3.GetColour()<<" "<< obj3.GetShape() <<" \n";
getchar();
}
The 2 errors i get are
\classes\classes3.cpp(76) : error C2228: left of '.GetColour' must have class/struct/union type
and
\classes\classes3.cpp(76) : error C2228: left of '.GetShape' must have class/struct/union type