-2
class employee {
        public :
            employee (char *inName, char *inPosition, double inSalary =0.0);
            ~employee();
            char getName()const;
            char getPosition()const;
            double getSalary()const;
            virtual void display();
        private :
            char name[40];
            char position[40];
            double salary;
        protected:
            void setName(char inName);
            void setPosition(char inPosition);
            void setSalary(double inSalary);
};
employee::employee(char *inName, char *inPosition, double inSalary){
    setName(*inName);
    setPosition(*inPosition);
    setSalary(inSalary);
}
//destructor
//setter
//getter
void employee::display(){
    cout<<"Employee Name Is     :"<<getName()<<endl;
    cout<<"Employee Position Is :"<<getPosition()<<endl;
    cout<<"Employee Salary  :"<<getSalary()<<endl;
}
int main{
    char *x ="bello";
    employee e1(x, "123",50);
    e1.display();
}

How could i possibly solve this problem as in my employee e1(x, "123",50), I have receive a message of: Deprecated conversion from string constant to 'char*. What is the possible solution?

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
Synetrix
  • 59
  • 2
  • 12
  • 2
    Most of your code is irrelevant. You could reproduce this in three lines of code. – juanchopanza Nov 30 '15 at 15:30
  • 4
    The message is pretty clear. The conversion from a string constant to `char*` is deprecated, so don't convert a string constant to `char*`. – Šimon Tóth Nov 30 '15 at 15:33
  • @Let_Me_Be but inserting employee e1("bello", "123",50) does not give me any output as well. Any correct format? – Synetrix Nov 30 '15 at 15:37
  • 4
    Prefer `std::string` over `char*`. – cdonat Nov 30 '15 at 15:37
  • @Synetrix Because you have the same issue at many points in your code. You need to fix it everywhere, not just in one of the places. – Šimon Tóth Nov 30 '15 at 15:40
  • There is a lot wrong with this code. `getX` and `setX` return and take `char`, not `char*` or strings. Really, use `std::string`. – MicroVirus Nov 30 '15 at 15:40
  • @Synetrix This is also wrong: `char getName()const;` `void setName(char inName);` you'll get only the first character copied into your data members. As already mentioned use `std::string` rather than raw character arrays. – πάντα ῥεῖ Nov 30 '15 at 15:40
  • 1
    Literally copy-pasting your title into google yields a bunch of explanations for this, including several answers on this very site. Please do some research before posting. – Baum mit Augen Nov 30 '15 at 16:12

1 Answers1

2

Well, this;

char *x ="bello";

should be:

const char *x ="bello";

the reason is that c++ string literals are of type const char[].

The same applies to (declaration and definition):

employee (char *inName,     char *inPosition, double inSalary =0.0);
          ^~~~here consts ~^~ 
marcinj
  • 48,511
  • 9
  • 79
  • 100