小编Lai*_*aif的帖子

未调用覆盖的虚拟方法

在下面的代码中,我试图覆盖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)

c++

3
推荐指数
1
解决办法
78
查看次数

为什么p:first-child伪类不适用于p元素的第一个孩子

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)

css css-selectors pseudo-class

2
推荐指数
1
解决办法
37
查看次数

C++“noskipws”没有按预期工作,如何正确允许字符串中有空格?

我希望能够输入一个完整的字符串,包括空格,然后打印该字符串。

为什么这段代码的行为不像我期望的那样?

代码

#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)

c++

1
推荐指数
1
解决办法
216
查看次数

如何根据我所在的页面突出显示导航栏

我试图根据我所在的页面突出显示导航栏,例如:

我目前所在的页面

我所在的下一页

如您所见,我移动到的页面已突出显示。我怎样才能在代码中做到这一点?

<div class="navbar" id="navbar_welcome">
  <a href="index.php?action=home" class="active"><i class="fas fa-home"></i>&nbspHome</a>
  <a href="index.php?action=home"><i class="fas fa-chart-line"></i>&nbspHistory</a>
  <a href="index.php?action=setting"><i class="fas fa-user"></i>&nbspProfile</a>
</div>
Run Code Online (Sandbox Code Playgroud)

html javascript css php jquery

0
推荐指数
1
解决办法
75
查看次数

标签 统计

c++ ×2

css ×2

css-selectors ×1

html ×1

javascript ×1

jquery ×1

php ×1

pseudo-class ×1