Sunday, June 18, 2017

How to get rid of compiler error-
deprecated conversion from string constant to ‘char*’
I got this compilation error while compiling the below code.

void ABC(char *strng) {};
ABC("Hello World");
void ABC(char *strng){};               //This code may compile but the window will crash on execution
char *strng1="Hellow World";

I find two solution for this...
void ABC(char *strng){};
char strng1[] ="Hellow World";

2. define const every where if the sting does no changes.
void ABC(const char *strng){};
const char *strng1 ="Hellow World";

Access the private data member variables of the class without friend function.
#include <iostream>
#include <string>
using namespace std;
class ABC
{ private:
   int a,b;
  void show() {
      cout<<"a="<<a<<"and b="<<b; }
int main()
    ABC obj;
    int *p_obj=(int*)&obj;
    *p_obj=10;                           // It will set the value of a to 10;
     *(p_obj+1) = 20;                 //It will set the value of b to 20.;

No comments:

Post a Comment