简体   繁体   中英

Why can I derived from a templated/generic class based on that type in C# / C++

Title probably doesn't make a lot of sense, so I'll start with some code:

class Foo : public std::vector<Foo>
{
};

...

Foo f;

f.push_back( Foo() );

Why is this allowed by the compiler? My brain is melting at this stage, so can anyone explain whether there are any reasons you would want to do this? Unfortunately I've just seen a similar pattern in some production C# code and wondered why anyone would use this pattern.

can anyone explain whether there are any reasons you would want to do this?

Curiously recurring template pattern .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM