开发者

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

开发者 https://www.devze.com 2022-12-27 14:40 出处:网络
Title probably doesn\'t make a lot of sense, so I\'ll start with some code: class Foo : public std::vector<Foo>

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 th开发者_StackOverflow中文版e 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消