考虑以下几个继承层的示例:
struct A {
void operator()(double x);
};
struct B: A {
using A::operator();
template <class... T> void operator()(T... x);
};
struct C: B {
using B::operator();
void operator()() const;
void operator()(int x) const;
};
struct D: C {
using C::operator();
void operator()();
};
重载决策是否完全像D
写成:
struct D {
void operator()(double x);
template <class... T> void operator()(T... x);
void operator()() const;
void operator()(int x) const;
void operator()();
};
或相反,编译器尝试在D
中找到工作重载,然后在C
,然后在B
,然后在A
?换句话说,继承是否在重载解析(对于没有相同签名的函数)中起任何作用?或者不是?
答案 0 :(得分:4)
一般规则是重载解析将考虑通过名称查找找到的声明集,而不考虑其他声明。
根据[namespace.udecl] / 1:
using-declaration 中的每个 using-declarator 都会在声明区域中引入一组声明。 其中出现 using-declaration 。由 using-declarator 引入的声明集可以通过以下方式找到 对 usingdeclarator 中的名称执行限定名称查找(6.4.3,13.2),但不包括 隐藏如下所述。
因此,operator()
范围内的D
的名称查找,D::operator()
以及 using-declaration ,必须以递归方式查找operator()
范围内的C
,它会找到两个C::operator()
以及 using-declaration ,依此类推。所以是的,在您的情况下,重载决策会将整套operator()
s视为候选。
答案 1 :(得分:1)
C::operator()
隐藏了父母的重载。
你必须使用<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="indyfolk.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></script>
<link href="https://fonts.googleapis.com/css?family=Lato:300" rel="stylesheet">
<script src=""></script>
<title>Indy Folk News</title>
</head>
<body>
<div class="topnav">
<div class="search-container">
<form action="/action_page.php">
<input type="text" placeholder="search" name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
<a class="active" href="#about">ABOUT</a>
<a href="#news">NEWS</a>
<a href="#events">EVENTS</a>
<a href="#contact">CONTACT</a>
</div>
<div class="banner">
<p>Providing News of Indy Folk Music,
<br>
Folk Art, Storytelling & Cultural News
<br>
to the Community
</p>
<button class="button button1">LEARN MORE</button> <button class="button button2">SEE EVENTS</button>
<div class="bottomhdr">
<div class="bottomtxt">
<p>GET UPDATES RIGHT TO YOUR INBOX</p>
</div>
<div class="email">
<form action="/action_page.php">
<input type="text" placeholder="enter your email address" name="search">
<button type="submit"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
</div>
<br>
<div class="row">
<h1>Recent Posts</h1>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>News Post Title</b></p>
<p><b>Posted by:</b> Poster Name</p>
<p><b>Date:</b> January 8, 2018</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button3">READ MORE</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>News Post Title</b></p>
<p><b>Posted by:</b> Poster Name</p>
<p><b>Date:</b> January 8, 2018</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button3">READ MORE</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>News Post Title</b></p>
<p><b>Posted by:</b> Poster Name</p>
<p><b>Date:</b> January 8, 2018</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button3">READ MORE</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>News Post Title</b></p>
<p><b>Posted by:</b> Poster Name</p>
<p><b>Date:</b> January 8, 2018</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button3">READ MORE</button>
</div>
</div>
<div class="row">
<div class="column" style="background-color:#ccc;"></div>
<div class="column" style="background-color:#ccc;"></div>
<div class="column"style="background-color:#ccc;"></div>
<div class="column"style="background-color:#ccc;"></div>
</div>
<br>
<div class="link">
<a href="" target="_blank">SEE ALL NEWS POSTS ></a>
</div>
<br>
<hr>
<br>
<div class="row1">
<h1>Upcoming Events</h1>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>Band Name</b></p>
<p><b>Date:</b> January 8, 2018</p>
<p><b>Location:</b> White Rabbit</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button4">GET TICKETS</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>Band Name</b></p>
<p><b>Date:</b> January 8, 2018</p>
<p><b>Location:</b> White Rabbit</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button4">GET TICKETS</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>Band Name</b></p>
<p><b>Date:</b> January 8, 2018</p>
<p><b>Location:</b> White Rabbit</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button4">GET TICKETS</button>
</div>
<div class="column"style="background-color:#D5D6D6;">
<img src="folkband.png">
<p><b>Band Name</b></p>
<p><b>Date:</b> January 8, 2018</p>
<p><b>Location:</b> White Rabbit</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus aliquam bibendum urna, eu dignissim nisi laoreet vitae. Morbi sed finibus nisi. Ut maximus, mi at eleifend luctus, nisi nisl fringilla arcu, ut interdum tellus sem vel ex. Sed congue metus et eleifend mollis. Aliquam erat volutpat. Etiam varius libero eget ligula convallis, in tempor orci congue. Vivamus quis enim tempor est pharetra sodales. Etiam ac nunc tempor ex rhoncus pulvinar vel vel quam. Pellentesque consectetur, turpis elementum ornare blandit, erat eros pharetra quam, sit amet tincidunt massa augue sit amet augue.</p>
<button class="button button4">GET TICKETS</button>
</div>
</div>
<br>
<br>
<div class="link">
<a href="" target="_blank">SEE ALL EVENTS ></a>
</div>
</body>
</html>
来写(和其他基础相同)。
然后所有重载都可见。