what means these warning?
"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"
i have 1 struture:
Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};
and heres how i add the values:
Code:
SetText *x=new SetText; x->PosX=5;
x->PosX=6;
x->Text ="hello mother";
why i recive that warning in: x->Text ="hello mother"; ?
Re: what means these warning?
Re: what means these warning?
Quote:
Originally Posted by
VictorN
but i think ,more and i resolve it;)
now the Text is string and what i did was recreate another var char pointer and then convert the values;)
Code:
char * writable = new char[p->Text.size() + 1];
std::copy(p->Text.begin(), p->Text.end(), writable);
int len = strlen(writable);
and now no warnings;)
thanks for all
Re: what means these warning?
Quote:
Originally Posted by
Cambalinho
"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"
i have 1 struture:
Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};
and heres how i add the values:
Code:
SetText *x=new SetText; x->PosX=5;
x->PosX=6;
x->Text ="hello mother";
why i recive that warning in: x->Text ="hello mother"; ?
Which compiler are you using for this? You are probably receiving this warning because you are allocating a const char array ("hello mother") to a non-const char pointer (char *Text). To get rid of the warning, try making Text a const char *
Code:
struct SetText{
int PosX;
int PosY;
const char *Text;
};
Re: what means these warning?
Quote:
Originally Posted by
2kaud
Which compiler are you using for this? You are probably receiving this warning because you are allocating a const char array ("hello mother") to a non-const char pointer (char *Text). To get rid of the warning, try making Text a const char *
Code:
struct SetText{
int PosX;
int PosY;
const char *Text;
};
thanks but i thot that the const was only for variables that we can't change their values;)
thanks for all
Re: what means these warning?
Quote:
Originally Posted by
Cambalinho
thanks but i thot that the const was only for variables that we can't change their values;)
thanks for all
Const is for variables for which you don't change their values. But you are passing a const string ("hello mother") that cannot be changed. Also, with your struct SetText it is very unlikely that you will be modifying Text so const char *Text is the better definition anyhow.:cool:
Re: what means these warning?
Quote:
Originally Posted by
2kaud
Const is for variables for which you don't change their values. But you are passing a const string ("hello mother") that cannot be changed. Also, with your struct SetText it is very unlikely that you will be modifying Text so const char *Text is the better definition anyhow.:cool:
thanks for all.. thanks to both
sorry, but seems that i can't Rate you again:(