相关疑难解决方法(0)

如何在派生类中访问基类中的所有隐藏名称?

从这个问题开始:

并考虑这个简化的代码:

#include <string>
#include <iostream>

class Abstract
{
public:
    virtual void method(int a)
    {
        std::cout << __PRETTY_FUNCTION__ << "a: " << a << std::endl;
    }
};

class Concrete : public Abstract
{
public:
    void method(char c, std::string s)
    {
        std::cout << __PRETTY_FUNCTION__ << "c: " << c << "; s: " << s << std::endl;
    }
};

int main()
{
    Concrete c;
    c.method(42);    // error: no matching function for call to 'Concrete::method(int)'
    c.method('a', std::string("S1_1"));

    Abstract *ptr = &c; …
Run Code Online (Sandbox Code Playgroud)

c++ using-declaration name-lookup name-hiding

5
推荐指数
0
解决办法
97
查看次数

标签 统计

c++ ×1

name-hiding ×1

name-lookup ×1

using-declaration ×1