在下面的代码中,我试图覆盖price()Taxed 和 Untaxed的函数,但是,它们都调用父虚拟函数而不是提供给它们的覆盖函数。我搞砸了什么?
头文件:
#ifndef PRODUCT_H
#define PRODUCT_H
#include <string>
#include <iostream>
class Product {
protected:
int _quantity;
double _cost;
std::string _name;
public:
Product(std::string name, double cost);
virtual ~Product();
void set_quantity(int quantity);
virtual double price() const;
friend std::ostream & operator<< (std::ostream &ost, const Product &product);
};
std::ostream & operator<< (std::ostream &ost, const Product &product);
class Taxed : public Product{
private:
static double _tax;
public:
using Product::Product;
virtual ~Taxed();
static void set_tax_rate(double sales_tax);
double price() const override;
};
class …Run Code Online (Sandbox Code Playgroud) CSS标记的pseudo类选择器(第一个孩子)适用于作为其父代的直接第一个孩子的所有p,为什么不适用于作为p本身的第一个直接元素的p标记。
p:first-child {
color: blue;
}Run Code Online (Sandbox Code Playgroud)
<body>
<p>This P is body's first Child.</p>
<p>This is body's second child.</p>
<div>
<p> This P is div's first Child </p>
<p> This is div's second child.</p>
</div>
<p>
<p> This P is P's first child :: Why it does not get pseudo class</p>
<p> This is P's second child </p>
</p>
</body>Run Code Online (Sandbox Code Playgroud)
我希望能够输入一个完整的字符串,包括空格,然后打印该字符串。
为什么这段代码的行为不像我期望的那样?
代码
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << "Enter your name:\n";
string name;
cin >> noskipws >> name;
cout << "Hello, " << name << "!";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出
Enter your name:
>tes test test
Hello, tes!
Run Code Online (Sandbox Code Playgroud) 我试图根据我所在的页面突出显示导航栏,例如:
到
如您所见,我移动到的页面已突出显示。我怎样才能在代码中做到这一点?
<div class="navbar" id="navbar_welcome">
<a href="index.php?action=home" class="active"><i class="fas fa-home"></i> Home</a>
<a href="index.php?action=home"><i class="fas fa-chart-line"></i> History</a>
<a href="index.php?action=setting"><i class="fas fa-user"></i> Profile</a>
</div>
Run Code Online (Sandbox Code Playgroud)