c++ - 虚函数问题

标签 c++ visual-studio-2008 virtual-functions

我在 VSTS 2008 中使用 native C++。有关虚函数的快速问题。在下面的示例中,如果我在 Derived 类中将 Foo 声明为“virtual void Foo()”或“void Foo()”,会有什么不同吗?对派生自类 Derived 的任何 future 类有任何影响吗?

class Base
{
public:

    Base()
    {
    }

    virtual void Foo()
    {
        cout << "In base" << endl;
    }
};

class Derived : public Base
{
public:

    Derived()
    {

    }

    void Foo()
    {
        cout << "In derived " << endl;
    }
};

最佳答案

没有区别。但为了可读性,我始终保持 visual

关于c++ - 虚函数问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2424967/

相关文章:

c++ - 每次调用负 0.6ns 的虚函数开销?

c++ - 虚函数本质上应该有一个定义吗?

visual-studio-2008 - 线程 'Win32 Thread'已退出,代码为-1073740777(0xc0000417)

visual-studio-2008 - 检查所有库和 dll 是否来自同一个版本?

c++ - CRTP 与作为接口(interface)或 mixin 的虚拟函数

c++ - 如何创建共享库特定的单例实例

c++ - 优化条件的方法 "if (m == 0 || n == 0)"

c++ - 嵌套模板函数的重载

c++ - 我可以使用不完整类型列表的迭代器吗?

c# - 使用 AddRange 将多个项目添加到组合框