locked
Can template specialization be used for base types in C++/CX?

    General discussion

  • I'd "like" to be able to specify a single specialized template for interfaces so I don't have to create a separate one for every interface I register in my "poor man's IOC" container (SpecializedTemplates.h).

    I created an IInterface which my IClassBase and ITest derive from but it was ignored - is there a trick or workaround that anyone is aware of to do this?

    I blog on the topic in more detail HERE


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    • Changed type Jesse Jiang Monday, April 8, 2013 3:08 AM
    Sunday, April 7, 2013 12:53 PM

All replies

  • I've tried a variety of tricks but couldn't think of anything that would do the trick. It seems to me like a strange test to do; I normally think of tests as things to catch erroneous behavior/results that the compiler could not catch.

    In this case the compiler will catch the lack of a concrete implementation of an interface class. But perhaps I'm misunderstanding the goal. If you could provide some more background around what exactly you are trying to test and why, maybe it'll help someone come up with a useable alternative.


    Visual C++ MVP | Website | Blog | @mikebmcl | Windows Store DirectX Game Template

    Monday, April 8, 2013 3:25 AM
  • Thank you Mike for your response/help.

    The test is unrelated to the question - I had performed Test Driven Development (TDD) for my Inversion Of Control (IOC) container and was doing a red-green refactor after replacing my TypeOf() template read moreIt was during TDD that I encountered the error so I captured the screen shot to provide a visual of the problem.

    What I am actually trying to do...  Where I can have a single GwnTemplates.h header file in my GwnLibraryTemplates project (which my GwnLibrary, GwnLibraryTest, and PasswordMgr projects reference), I have to have a separate SpecializedTemplates.h header file for applicable interfaces within each project; the basis of IOC is coding to an interface.   My objective would be to avoid having to create a specialized template for each interface I Resolve() as it will generate a compiler error if I don't.

    Note: the following image borrowed from this blog to help visualize this response:


    MCAD.NET C# - http://www.Global-webnet.com/Blog


    • Edited by BillKrat1 Monday, April 8, 2013 8:36 AM
    Monday, April 8, 2013 8:33 AM