I have been learning c++ since the last three months and i am currently stuck on some twisted warning which my compiler is giving to me. The warning states the following: "ISO C++ forbids converting a const string to char*". I am using Eclipse Helios 2011 32-bit IDE. When i declare both the name and s as string it gives me an error stating: "cannot convert a string to char *". A little insight and a slight hint regarding this problem would be appreciated.
For code it is as follows:
#include<iostream>
#include<cstring>
using namespace std;
class person
{
char name[20];
float age;
public:
person(char *s,float a)
{
strcpy(name,s);
age=a;
}
person& greater(person &x)
{
if(x.age>=age)
return x;
else
return *this;
}
void display()
{
cout<<"Name "<<name<<endl;
cout<<"Age "<<age<<endl;
}
};
int main()
{
person P1("John",37.40) ,P2("Kramer",40.01),P3("Jason",57.80);
person P=P1.greater(P2);
cout<<"Elder person between P1 and P2 is: "<<endl;
P.display();
person P4=P2.greater(P3);
cout<<"Elder person between P2 and P3 is: "<<endl;
P4.display();
}