Note that there are some explanatory texts on larger screens.

plurals
  1. POATL COM - How To Reuse Code for Interface Method
    primarykey
    data
    text
    <p>I have several interfaces, e.g. IA, IB, IC, and so on, that share common properties, e.g. Site. I would like to know how to reuse code for these interfaces (please save me the answer on COM aggregation).</p> <p>Current implementation is as follows:</p> <pre><code>class CA // ATL specific... { STDMETHODIMP get_Site(...) {...} STDMETHODIMP put_Site(...) {...} } class BA // ATL specific... { STDMETHODIMP get_Site(...) {...} STDMETHODIMP put_Site(...) {...} } class CC // ATL specific... { STDMETHODIMP get_Site(...) {...} STDMETHODIMP put_Site(...) {...} } </code></pre> <p>What I want to achieve (but cannot) is as follows. </p> <pre><code>template&lt;typename T&gt; class SharedProperties { STDMETHODIMP get_Site(...) {...} STDMETHODIMP put_Site(...) {...} } class CA : // ATL specific... SharedProperties&lt;CA&gt; { // properties are inherited and are accessible from IC } class BA // ATL specific... SharedProperties&lt;CB&gt; { // properties are inherited and are accessible from IB } class CC // ATL specific... SharedProperties&lt;CC&gt; { // properties are inherited and are accessible from IA } </code></pre> <p>I came across this idea after reading up (<a href="http://vcfaq.mvps.org/com/7.htm" rel="nofollow">http://vcfaq.mvps.org/com/7.htm</a>) but the site does not have a working example and no matter how much I tried I could not get it to work. I keep getting "Cannot instantiate abstract class" because the pure virtual functions get_Site and put_Site are not implemented (as per the second snippet).</p> <p><strong>EDIT</strong> Do note that I am using VS2010. Sample implementation below:</p> <pre><code>class ATL_NO_VTABLE CArticle : public CComObjectRootEx&lt;CComSingleThreadModel&gt;, public CComCoClass&lt;CArticle, &amp;CLSID_Article&gt;, public IDispatchImpl&lt;IArticle, &amp;IID_IArticle, &amp;LIBID_GeodeEdiLib, /*wMajor =*/ 1, /*wMinor =*/ 0&gt; { public: CArticle() { } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload