locked
class inheritance

    Question

  • Hi, this code do not compile anymore with the latest VS2012 version.

    Is it still possible to create this kind of class inheritance ?

    public ref class Resource // <-- Error : C4585
    {
    
    protected private:
    
    	Resource( );
    
    public :
    			
    	virtual ~Resource( );
    
    	// ...
    };
    
    public ref class Brush sealed : Resource
    {
    
    private:
    
    	Brush( );
    
    public :
    			
    	virtual ~Brush( );
    
    	// ...
    };

    Monday, August 20, 2012 3:07 AM

Answers

  • Please see the migration doc http://win8.ms/rtmdevdoc for more details.

    public ref classes must inherit from a WinRT base and in this release that is scoped to most XAML scenarios.  If Resource inherits from DependencyObject you should get past the compiler error.


    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marked as answer by t-n-x Monday, August 20, 2012 4:49 PM
    Monday, August 20, 2012 6:10 AM
  • XAML is likely the primary use case and hence the example.  If this is just a WinRT component, then you may have to think differently in the design.  Does it have to be public, etc. -- you can see the details (and some suggestions) in the doc http://win8.ms/rtmdevdoc -- see about page 29

    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marked as answer by t-n-x Monday, August 20, 2012 4:48 PM
    Monday, August 20, 2012 3:47 PM

All replies

  • Please see the migration doc http://win8.ms/rtmdevdoc for more details.

    public ref classes must inherit from a WinRT base and in this release that is scoped to most XAML scenarios.  If Resource inherits from DependencyObject you should get past the compiler error.


    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marked as answer by t-n-x Monday, August 20, 2012 4:49 PM
    Monday, August 20, 2012 6:10 AM
  • But then you cannot use any of your class in thread ... thanks MS :-/
    Monday, August 20, 2012 8:36 AM
  • Thanks for the answer.. my component has nothing to do with XAML, does it means all my code is now obsolete ?

    Monday, August 20, 2012 3:18 PM
  • XAML is likely the primary use case and hence the example.  If this is just a WinRT component, then you may have to think differently in the design.  Does it have to be public, etc. -- you can see the details (and some suggestions) in the doc http://win8.ms/rtmdevdoc -- see about page 29

    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marked as answer by t-n-x Monday, August 20, 2012 4:48 PM
    Monday, August 20, 2012 3:47 PM
  • Hi Tim,

    Deriving from DependencyObject causes issue during Unit Test (ref this link).  For those of us that would like to implement an enterprise pattern, i.e., MVVM or MVPVM this could be a blocking issue, particularly if we want to do TDD.   Is there not a class that we can derive from?

    Best regards

    Bill


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

    Saturday, August 25, 2012 3:05 PM
  • XAML is likely the primary use case and hence the example.  If this is just a WinRT component, then you may have to think differently in the design.  Does it have to be public, etc. -- you can see the details (and some suggestions) in the doc http://win8.ms/rtmdevdoc -- see about page 29


    This response was instrumental in helping me come up with "a solution"; I had to change my thinking... 
    I blog about it HERE

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

    Sunday, August 26, 2012 5:14 PM