我对 C++ 中的 RTTI 机制有些困惑。
假设有类 A 和继承自 A 的类 B。 现在考虑以下代码:
B* b = new B();
A* a = dynamic_cast<A*>(b);
Run Code Online (Sandbox Code Playgroud)
我知道具有虚方法的多态类有虚表和 vptr,但我认为指针只提供有关虚函数的信息。程序如何在运行时知道 b 的类型,使用 vptr 和 vtables?
在 linux 中为每个进程保留不同的内核堆栈有什么意义?
为什么不只保留一个堆栈供内核使用?
在Java中执行以下操作的限制背后的逻辑是什么?
public class genericClass<T>{
void foo(){
T t = new T(); //Not allowed
}
}
Run Code Online (Sandbox Code Playgroud) 我想问一下,没有实现虚函数有问题吗?例如:
class Function {
public:
virtual ~Function() {}
virtual double value(double x) const = 0;
virtual Function* clone() const = 0;
protected:
virtual void print(ostream& os) const = 0;
friend ostream& operator<<(ostream& os, const Function& f);
};
Run Code Online (Sandbox Code Playgroud)
在Function的派生类中,如果没有实现clone,它会给出编译错误吗?或者,如果我尝试调用derived.clone(),它会是运行时错误吗?
c++ ×2
generics ×1
inheritance ×1
java ×1
linux ×1
linux-kernel ×1
polymorphism ×1
process ×1
rtti ×1
stack ×1