c++ - Error c2036: unknown size only occurring in some situations -


Let's compile the code given below, even though I was complaining to the compiler that the size of Do not know fu However, if I change the #include with the advance declaration of bar , then it is not compiled for this reason

I know that FU is definately declared only because if Foo * muffu; is converted to Foo MyFoo; It does not compile why this error occurs only with a vector of one type of objects, but not others?

Using Visual Studio Express 2013.

  #include "Bar.h" square fu; Class Myclass {Foo * Mafu; Std :: vector & lt; Foo & gt; Less important things; Std :: vector & lt; Bar & gt; Bars; };  

And in itself, there is no reason that the template type must complete the argument type (Actually, 14.3.1 / 2 clearly states that this is not the case).

This type of requirement comes from how it is used within the definition of your type of template (in this case, std :: vector ). For example, [C ++ 11: 20.7.1 / 5] indicates that a std :: unique_ptr & lt; T & gt; T > unique_ptr ; This is clearly stated because.

You feel that as soon as you try to do something do with your vector, you will need it T complete The problem is detectable at the compile time because it comes down to all of the templates immediately, so your compiler will be in proper form and when necessary.

Vector killers are usually one of those things.

So,:

  #include & lt; Vector & gt; Square fu; Class bar; Std :: vector & lt; Foo & gt; Less important things; Std :: vector & lt; Bar & gt; Bars; Error: Invalid incomplete type 'square foo' 
Invalid use of error: invalid usage of 'class bar' invalid usage / blockquote>

only then When I use those sections as those members who are never used, because vector destructors are never applicable and therefore never template-present:

  #include & lt; Vector & gt; Square fu; Class bar; Square t {std :: vector & lt; Foo & gt; Less important things; Std :: vector & lt; Bar & gt; Bars; }; Whatever your implementation, it will be the same for both  foo  and  times ; If you are seeing a difference between them, then you have to do something different with the  bar  that you have not shown to us. 


Comments