【问题标题】:Overloaded virtual function warning重载虚函数警告
【发布时间】:2017-08-12 17:37:27
【问题描述】:

我应该如何处理现在无法编译的这段代码?我应该加void funccall(const String e);吗?

struct Base
{
     virtual void funccall(const String e = "");
};

struct Derived: public Base {
    using Base::funccall;
    void funccall();
    void funccall(char* e, int index);
};

【问题讨论】:

  • 请提供minimal reproducible example,如果您遇到编译错误,请提供这些错误的全文。照原样,您的代码会很好地完成。
  • 请发布错误信息或警告。
  • 投票结束,因为没有错误消息,这个问题是无法回答的。

标签: c++ clang warnings


【解决方案1】:

我的猜测是你必须定义一个纯虚函数

struct Base
{
     virtual void funccall(const String e = "")=0;
};

或为此方法定义一个主体

struct Base
{
     virtual void funccall(const String e = ""){};
};

添加到帖子:

#include "stdafx.h"
#include <string>

class base
{
public:
    virtual void funccall(const std::string e = "") {}
};
class derived : public base
{

    void funccall() {};
    void funccall(char *e, int index) {};
};

int main()
{
    return 0;
}

【讨论】:

  • 另外我会使用类而不是结构。无论如何,我尝试使用 std::string 而不是 String。你需要包括
猜你喜欢
  • 2013-09-02
  • 2021-10-16
  • 1970-01-01
  • 2017-08-06
  • 2023-01-07
  • 2017-02-07
  • 1970-01-01
  • 2014-02-23
相关资源
最近更新 更多