Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualMatt-D

Posted 03 August 2013 - 04:12 PM

Since you're only using "Buffer" type indirectly, i.e., as a "Buffer *" (ptr-to-Buffer), I suppose you could try a workaround (if you're willing to change your ConstantBuffer class), with forward declaration of "SMatrixBuffer" and using "SMatrixBuffer *" as a template argument in the instantiation. Beforehand, you'd need an explicit template instantiation in the same translation unit (extra or existing file, whatever you find most convenient) that has access to the forward-declared template argument.

 

For more details / examples, see:

http://www.network-theory.co.uk/docs/gccintro/gccintro_60.html

http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc16explicit_instantiation.htm

http://en.cppreference.com/w/cpp/language/class_template#Explicit_instantiation

 

Since you're only ever going to use incomplete types, this will even work with smart pointers, like std::unique_ptr (using which you should strongly consider, since it's zero-overhead anyway -- otherwise, by leaving raw pointers everywhere you're keeping your ownership semantics assumptions unstated, undocumented, and unenforced, which is rather bad):

http://stackoverflow.com/questions/10065384/instantiation-of-a-list-with-an-incomplete-type-in-a-typedef

 

If it sounds involved, it's because it is ;-) If you're fine with moving to a header-only template implementation, it's probably the simpler / recommended way.

In any case, reconsider using raw pointers, http://klmr.me/slides/modern-cpp/ ;-)


#1Matt-D

Posted 03 August 2013 - 04:11 PM

Since you're only using "Buffer" type indirectly, i.e., as a "Buffer *" (ptr-to-Buffer), I suppose you could try a workaround (if you're willing to change your ConstantBuffer class), with forward declaration of "SMatrixBuffer" and using "SMatrixBuffer *" as a template argument in the instantiation. Beforehand, you'd need an explicit template instantiation in the same translation unit (extra or existing file, whatever you find most convenient) that has access to the forward-declared template argument.

 

For more details / examples, see:

http://www.network-theory.co.uk/docs/gccintro/gccintro_60.html

http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc16explicit_instantiation.htm

http://en.cppreference.com/w/cpp/language/class_template#Explicit_instantiation

 

This will even work with smart pointers, like unique_ptr (using which you should strongly consider, since it's zero-overhead anyway -- otherwise, by leaving raw pointers everywhere you're keeping your ownership semantics assumptions unstated, undocumented, and unenforced, which is rather bad):

http://stackoverflow.com/questions/10065384/instantiation-of-a-list-with-an-incomplete-type-in-a-typedef

 

If it sounds involved, it's because it is ;-) If you're fine with moving to a header-only template implementation, it's probably the simpler / recommended way.

In any case, reconsider using raw pointers, http://klmr.me/slides/modern-cpp/ ;-)


PARTNERS