我正在尝试使用詹金斯。但是,当我阅读声明性管道语法时,我对“代理”感到困惑(https://jenkins.io/doc/book/pipeline/syntax/#scripted-pipeline)。
据我所知,当基类具有虚函数时,C ++可以获取对象动态类型的准确信息。
class Base
{
public:
Base() {}
~Base() { std::cout << "Base Destructed" << std::endl; }
virtual void f() {}
};
class Derived : public Base
{
public:
Derived() {}
~Derived() { std::cout << "Derived Destructed" << std::endl; }
};
void PrintTypeName(Base *p)
{
std::cout << typeid(*p).name() << std::endl;
}
int main()
{
Base *p = new Derived();
PrintTypeName(p);
delete p;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码可以打印正确的对象类型,但是为什么它不能调用正确的析构函数。
我在g ++和Windows编译器上对其进行了测试,它们给出了相同的结果。我知道如果我使Base析构函数virtual,它可以正确地分解。
但是我想知道为什么不通过调用析构函数typeid。