Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Polyrmophism
struct X { X(int x) : x_(x) {} int x_; virtual ~X() { } }; template <int N> struct Y: X { Y(int y, int x) : X(x), y_(y) { } int y_; int n_{N}; }; #include <iostream> int main() { Y<1> y1(1, 3); Y<2> y2(2, 4); X *pxa, *pxb; pxa = &y1; std::cout << pxa->x_ << std::endl; pxb = &y2; std::cout << pxb->x_ << std::endl; *pxa = *pxb; std::cout << pxa->x_ << std::endl; std::cout << dynamic_cast<Y<1>*>(pxa)->y_ << std::endl; // Line below will crash because *pxa is not a Y<2> std::cout << dynamic_cast<Y<2>*>(pxa)->y_ << std::endl; }
run
|
edit
|
history
|
help
0
134
rotation
Such case
顺序表的实现——动态分配
Find the row with max ones
project
base and derr con
Arithmetic
Tree
10 wizards-DFS_vector