维基百科并没有详细描述这个特性是如何实现的:
到目前为止,我的理解是。例如,假设我有:
class Car {
speed: 0
drive(speed) {
this.speed = speed
}
}
car = new Car
car.drive(10)
当我创建一个新的car实例时,您可以将它想象成一个结构,可能包含在运行时中的类型:
type: Car<#123> // <- memory address 123 starts this record
speed: 10
但是该方法可能存储在其他地方,比如表中。在表中查找car类型,然后对该
我一直在学习C++模板,并且遇到了一些奇怪的行为。考虑一下这个类结构(从我的原始代码中去掉):
class A {
public:
std::vector <int> vec;
};
template <typename T> class B : public A { };
template <typename T> class C : public B<T> {
public:
using A::vec;
int test() {
return vec[1]; // OK
}
在C++中,您可以这样做
enum class Colors {black, blue, green, cyan, red, purple, yellow, white};
Colors mycolor;
mycolor = Colors::blue; // this is what I want to do
在C中,可以使用EnumName::tag引用枚举吗?