warning: conversion from string

2020-12-03  本文已影响0人  夙小叶
截屏2020-12-03 上午10.14.32.png
class Attack
{
    public:
        char *target_ip;
        int target_port;

        int run(void)
        {
            std::cout << "[*] Target IP : " << target_ip << std::endl;
            std::cout << "[*] Target Port : " << target_port << std::endl;

            return 0;
        }
};

警告

class_inherit.cpp:22:23: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    bool email_status = false;
                      ^
class_inherit.cpp:40:22: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
    hack.target_ip = "192.168.1.101";
                     ^
class_inherit.cpp:45:21: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
    web.target_ip = "192.168.1.102";
                    ^
class_inherit.cpp:50:24: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
    re_run.target_ip = "10.2.2.11";
                       ^
class_inherit.cpp:53:23: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
    re_run.send_email("evil@email.com");
                      ^
5 warnings generated.

虽然可以正常生成二进制文件使用,但还是看不过眼,解决方法:

const

const char *target_ip;

使用 string 库和关键字

#include <string>

std::string target_ip;
上一篇下一篇

猜你喜欢

热点阅读