c++ - Having trouble storing a CRTP based class in a vector -


I'm not sure that it can be done, just im delving into templates, maybe my understanding is a little wrong.

I have a Platoon of soldiers, inherited from a formation to take the property of Platoon, but because I can have many structures, as I can think I CRTP is used to make structures, hopefully I can make Platon a vector to store platoon, but obviously when I make a platon, then it is vect In is not stored, "are unrelated"

Is there any way around this? I read about "Weinier" who are similar and they work with arrays, but I can not make it difficult to work, maybe I'm missing something

here's some code : (Sorry about formatting, this code is in my post but is not showing for some reason)

  template  

Then I use the platin class to use these structures so that Plato can get the relevant SetupFormat () function:

  template & Lt; Class structure & gt; Class Platoon: Public Structure {Public: **** Platoon code here};  

Everything is great and is expected by this point as well.

Now, as I can have multiple platons in my normal, I need to store Plato.

  Type is Platoon & lt; Iformation & lt; & Gt; & Gt; TPlatoon; // FAIL typedef std :: vector & lt; TPlatoon * & gt; TPlatoons; TPlatoon m_pPlatons m_pPlatoons.push_back (new Platten  

typedif platoon & lt; IFormation & lt; >> Tipton; Fails because I need to specify the template parameter, specifying this will allow me to store the plots made with only that template parameter.

So I again created FormationBase

  class formationbase {Public: Virtual Bull IsFull () = 0; Virtual Zero SetupFormatation (Study :: Vector & lt; Mistolizer * & gt; & amp; _soldierList) = 0; };  

and Iformation publicly made it successor, and then

  typedef platoon & lt; Iformation & LT; FormBase & gt; & Gt; TPlatoon;  

But there is still no love.

Now in my search I have not got the information which says that it is possible - it is not possible - or not possible.

C ++ does not allow easy access to polynomials at time of compilation time and running. You are right that your vector is capable of catching only one type. You want to keep your vector an indicator with a non-template type, or you can change the design to not use the vector.

If you want CRTP'd classes publicly formationbase , then vector to std :: vector & lt; FormationBase * & gt; Must be . It is impossible to go back from the Runtime Class formationbase with the Complex Time template parameter.

Looks relatively consistent in keeping your data in view and how you want to change only the alignment of soldiers and units in the battlefield, I consider using the strategy pattern to specify the setup format By using a separate, nonpolymorphic square, you will store it in vector.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -