小编Mur*_*mal的帖子

具有迭代器和继承的STL容器

这是一个示例C++问题,以找出结果.

#include <iostream>
#include <vector>

class A
{
public:
    A(int n = 0) : m_n(n) { }

public:
    virtual int f() const { return m_n; }
    virtual ~A() { }

protected:
    int m_n;
};

class B
    : public A
{
public:
    B(int n = 0) : A(n) { }

public:
    virtual int f() const { return m_n + 1; }
};

int main()
{
    const A a(1);
    const B b(3);
    const A *x[2] = { &a, &b };
    typedef std::vector<A> …
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl object-slicing c++11

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

标签 统计

c++ ×1

c++11 ×1

iterator ×1

object-slicing ×1

stl ×1