locked
A public constructor cannot contain an 'out' parameter or 'WriteOnlyArray<T>'

    Question

  • Here's the definition of the class

        public ref class Direct3DImageSource sealed : Windows::UI::Xaml::Media::Imaging::SurfaceImageSource
        {
        public:
            Direct3DImageSource(unsigned char *texels, int pixelWidth, int pixelHeight, bool isOpaque);
    
            void BeginDraw();
            void EndDraw();
    
            void Clear(Windows::UI::Color color);
            void Render();
    
        private protected:
            void CreateDeviceIndependentResources();
            void CreateDeviceResources();
    
            Microsoft::WRL::ComPtr<ISurfaceImageSourceNative>   m_sisNative;
    
            // Direct3D objects
            Microsoft::WRL::ComPtr<ID3D11Device>                m_d3dDevice;
            Microsoft::WRL::ComPtr<ID3D11DeviceContext>         m_d3dContext;
            D3D_FEATURE_LEVEL                                   m_featureLevel;
            Microsoft::WRL::ComPtr<ID3D11RenderTargetView>      m_renderTargetView;
            Microsoft::WRL::ComPtr<ID3D11DepthStencilView>      m_depthStencilView;
            Microsoft::WRL::ComPtr<ID3D11VertexShader>          m_vertexShader;
            Microsoft::WRL::ComPtr<ID3D11PixelShader>           m_pixelShader;
            Microsoft::WRL::ComPtr<ID3D11InputLayout>           m_inputLayout;
            Microsoft::WRL::ComPtr<ID3D11Buffer>                m_vertexBuffer;
            Microsoft::WRL::ComPtr<ID3D11Buffer>                m_indexBuffer;
            Microsoft::WRL::ComPtr<ID3D11Buffer>                m_constantBuffer;
            Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>    m_textureSRV;
            Microsoft::WRL::ComPtr<ID3D11SamplerState>          m_sampler;
    
            ModelViewProjectionConstantBuffer                   m_constantBufferData;
    
            uint32                                              m_indexCount;
    
            int                                                 m_width;
            int                                                 m_height;
        };
    

    It seems that the first parameter (unsigned char*) of the constructor results in the compiler error.

    Friday, October 19, 2012 9:08 AM

Answers

  • In Windows 8 RTM,

        public:
            Direct3DImageSource(unsigned char *texels, int pixelWidth, int pixelHeight, bool isOpaque);

    The Windows Runtime specification forbids public constructors from having [out] parameters; the C++ compiler now enforces this behavior.

    Mark these constructors with an internal visibility.

    • Marked as answer by Leonard Friday, October 19, 2012 2:16 PM
    Friday, October 19, 2012 9:48 AM
  • "error: error C2035: a non-virtual destructor with 'internal' accessibility is not allowed for this type. "

    Define non-virtual destructor with public accessibility are not allowed in Windows 8 RTM (Windows 8 RP had allowed it).  Destructors are now restricted to only the following combinations of accessibility and virtual:

        • public and virtual (allowed on sealed or unsealed types)
        • protected private and non-virtual (only allowed on unsealed types)
        • private and non-virtual (allowed only on sealed types)

    No other combinations of virtual and accessibility will be permitted. 

    You can modify your code snapped like followings....

    namespace D3DImageSource{
    
       public ref class Direct3DImageSource sealed : Windows::UI::Xaml::Media::Imaging::SurfaceImageSource
        {
    	public:
    		virtual ~Direct3DImageSource() { free(m_teximagepixels); }
    
        internal:
            Direct3DImageSource(unsigned char*texels, int pixelWidth, int pixelHeight, bool isOpaque);
           
    
        private protected:
            unsigned char* m_teximagepixels;
    		 
        };
    
    }

    • Marked as answer by Leonard Friday, October 19, 2012 2:16 PM
    Friday, October 19, 2012 2:04 PM

All replies

  • In Windows 8 RTM,

        public:
            Direct3DImageSource(unsigned char *texels, int pixelWidth, int pixelHeight, bool isOpaque);

    The Windows Runtime specification forbids public constructors from having [out] parameters; the C++ compiler now enforces this behavior.

    Mark these constructors with an internal visibility.

    • Marked as answer by Leonard Friday, October 19, 2012 2:16 PM
    Friday, October 19, 2012 9:48 AM
  • Thanks very much Mokarrom, it works.

    Now I have another issue. As there is a pointer member variable in the class, I need to delete this pointer member in class destructor, but doing this trigger another compiler error: error C2035: a non-virtual destructor with 'internal' accessibility is not allowed for this type. The slight modification to the class is

        public ref class Direct3DImageSource sealed : Windows::UI::Xaml::Media::Imaging::SurfaceImageSource
        {
        internal:
            Direct3DImageSource(unsigned char*texels, int pixelWidth, int pixelHeight, bool isOpaque);
            ~Direct3DImageSource() { free(m_teximagepixels); }
    
        private protected:
            nsigned char* m_teximagepixels;
        };
    

    Friday, October 19, 2012 1:40 PM
  • "error: error C2035: a non-virtual destructor with 'internal' accessibility is not allowed for this type. "

    Define non-virtual destructor with public accessibility are not allowed in Windows 8 RTM (Windows 8 RP had allowed it).  Destructors are now restricted to only the following combinations of accessibility and virtual:

        • public and virtual (allowed on sealed or unsealed types)
        • protected private and non-virtual (only allowed on unsealed types)
        • private and non-virtual (allowed only on sealed types)

    No other combinations of virtual and accessibility will be permitted. 

    You can modify your code snapped like followings....

    namespace D3DImageSource{
    
       public ref class Direct3DImageSource sealed : Windows::UI::Xaml::Media::Imaging::SurfaceImageSource
        {
    	public:
    		virtual ~Direct3DImageSource() { free(m_teximagepixels); }
    
        internal:
            Direct3DImageSource(unsigned char*texels, int pixelWidth, int pixelHeight, bool isOpaque);
           
    
        private protected:
            unsigned char* m_teximagepixels;
    		 
        };
    
    }

    • Marked as answer by Leonard Friday, October 19, 2012 2:16 PM
    Friday, October 19, 2012 2:04 PM
  • Thanks again Mokarrom, it works. You must be a genious.

    Friday, October 19, 2012 2:15 PM