We need an answer to the question why the following code is correct and give an example of the code:

class A <T>{} class B: A<B>{} //тут ошибка VS намекает на - циклическую зависимость //class c: c {} 

Answer: This is a typical implementation of the CRTP technique.

  • What is the full text of the error? on which line swears? what version of the studio? - Grundy
  • And how do you imagine the inheritance from yourself? - Grundy
  • We need an answer to the question why the first two lines are correct. Error led to the overall picture. - Kans
  • why the first two lines are correct - because this is the correct inheritance. - Grundy
  • and where (for what) can this be applied? for understanding - Kans

1 answer 1

This is a typical implementation of the CRTP technique that came from C ++. Why is this correct? And why, actually, no? After all, we do not create any cyclic dependencies, we simply specify ourselves as a generalized parameter. But note, we point ourselves not to ourselves, but to another class, even if it is a parent. Not to say that I know how it is used in C #, but in C ++ it is a very common practice. If interested, you can read my article on CRTP in C ++ , and also I found a short article on the use of CRTP in C # at Habrahabr.