加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 为什么这个函数重载不起作用?

发布时间:2020-12-16 10:39:33 所属栏目:百科 来源:网络整理
导读:class CConfFile{ public: CConfFile(const std::string FileName); ~CConfFile(); ... std::string GetString(const std::string Section,const std::string Key); void GetString(const std::string Section,const std::string Key,char *Buffer,unsigned
class CConfFile
{
    public:
        CConfFile(const std::string &FileName);
        ~CConfFile();
        ...
        std::string GetString(const std::string &Section,const std::string &Key);
        void GetString(const std::string &Section,const std::string &Key,char *Buffer,unsigned int BufferSize);
        ...
}

string CConfFile::GetString(const string &Section,const string &Key)
{
    return GetKeyValue(Section,Key);
}

void GetString(const string &Section,const string &Key,unsigned int BufferSize)
{
    string Str = GetString(Section,Key);     // *** ERROR ***
    strncpy(Buffer,Str.c_str(),Str.size());
}

为什么在第二个函数中得到的函数’void GetString(const std :: string&,const std :: string&,char *,unsigned int)’的参数错误太少?

谢谢

解决方法

因为顾名思义,CConFile :: GetString()是一个类成员函数,不能像你在第二个函数中调用它那样访问它.
您声明的另一个函数Ge??tString()是一个全局函数.

你忘了将CConFile ::添加到第二个函数中……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读